Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7851713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T19:14:54+00:00 2026-06-02T19:14:54+00:00

I was debugging a program when I came across the following code I had

  • 0

I was debugging a program when I came across the following code I had erroneously typed similar to the following:

//Original (wrong)
std::string first("Hello");
std::string second = first + second;

//Instead of this (correct)
std::string first("Hello");
std::string second = first + something_else;

Obviously I wasn’t trying to do this (I can’t think why anyone would want to do this), but it got me thinking. It doesn’t look like the original should work, and I would assume it is undefined. Indeed, this was the source of my problem.

To make the problem more general, consider the following:

SomeType a;
SomeType b = a + b;

Is the behavior undefined simply because b is not yet initialized (see this answer)?

If the behavior is undefined, then my real question is, why?

Is this only undefined for certain standard containers, like std::string, or is this undefined in a more general sense (STL classes, user-defined classes, PODs, fundamental types)?

What part of the standard applies to this?

Assume this is c++11, if necessary.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T19:14:54+00:00Added an answer on June 2, 2026 at 7:14 pm

    The C++11 standard has this to say about the scope of a newly declared name:

    3.3.2 Point of declaration [basic.scope.pdecl]

    The point of declaration for a name is immediately after its complete
    declarator (Clause 8) and before its initializer (if any), except as
    noted below. [ Example:

    int x = 12;
    { int x = x; }
    

    Here the second x is initialized with its own (indeterminate) value. —
    end example ]

    There is similar wording in prior C++ standards.

    Off the top of my head, one rationale I can think of is that the name could be used in an initializer expression that takes the address of the object.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While debugging a program using I came across a pecular behavior. I am running
While debugging one of the program's core dump I came across the scenario where
I have a C/ncurses program that I'm debugging/maintaining. This program does ripoffline twice: first,
Last week I was a debugging a code and a weird situation came up:
I'm getting the following error after I start debugging my program. Do you know
I'm debugging a program (VS2008), and I was stepping through lines of code. I
I have been debugging a program for some time. The code below is part
Whenever I am debugging a java program, I have to have the code indented!
I have a debugging program which I've written to attach to a process and
I am now debugging a program that utilizes many different threads. There is an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.