On Thu, Apr 25, 2013 at 11:03 AM, Marc Glisse
On Thu, 25 Apr 2013, Jeffrey Lee Hellrung, Jr. wrote:
T& a = b + c;
you'll get a compiler error with (A) or (B) and a runtime error with (C).
Er, no. That might be true with Microsoft's compiler and its extra "features", but regular compilers will complain:
error: invalid initialization of non-const reference of type 'T&' from an rvalue of type 'T'
Are you sure we're talking about the same thing? This looks like the kind of error that (A) or (B) would produce; would not (C) say something like
invalid initialization of non-const reference of type 'T&' from type 'T&&'
???
I swear I just tried a T& y = static_cast
(x) on gcc and finding it compiled fine. I just tried to compile this program with g++ -std=c++0x -Wall -c test.cc for versions of gcc: 4.4, 4.6, 4.7, and 4.9 and they all rejected it with pretty much the same error message. I don't understand what the difference can be with your tests :-(
struct A{}; void f(){ A a; A&r=static_cast(a); }
And for the record, clang++'s error message:
error: non-const lvalue reference to type 'A' cannot bind to a temporary of type 'A'
Yeah I probably tried it too quickly and screwed something up; I get errors now. Thanks for setting me straight! - Jeff