On OS X, simple C++ program gives incorrect results (which are a result of command-line options ‘c++03’ vs ‘c++11’)

Firstly, the expected difference in behaviour is because the operator<<(std::ostream&, const char*) overload (it’s actually a function template specialization, but nevermind for now) has a parameter of type std::ostream& and an lvalue reference can only bind to an lvalue, and in your example the stream is an rvalue so that overload can’t be used. In … Read more

Why is taking the address of a temporary illegal?

&std::string(“Hello World”) The problem with this isn’t that std::string(“Hello World”) yields a temporary object. The problem is that the expression std::string(“Hello World”) is an rvalue expression that refers to a temporary object. You cannot take the address of an rvalue because not all rvalues have addresses (and not all rvalues are objects). Consider the following: … Read more

Is it valid to bind non-const lvalue-references to rvalues in C++ 11?(modified)

should that work in c++11? No, it should not. Foo is a custom class, I don’t understand why the first two line compiles It compiles only with MSVC. MSVC has an (arguably useful) compiler extension that allows binding lvalues of user-defined types to rvalues, but the Standard itself forbids this. See, for instance, this live … Read more

What is the value category of the operands of C++ operators when unspecified?

Yes, it’s ill-specified and has been covered before. Basically, every time an lvalue expression is required is enumerated, so we assume that every other operand must be a prvalue expression. So to answer your questions: A prvalue. If it’s not specified, it’s a prvalue. The note that is quoted in the linked answer seems to … Read more