Binding temporary to a lvalue reference

c++, compiler-construction, lvalue, rvalue

Solution

It used to compile in VC6 compiler, so I guess to maintain backward comptibility VS2008 is supporting this non-standard extension. Try with /Za (disable language extension) flag, you should get an error then.

Problem

I have the following code ``` string three() { return "three"; } void mutate(string& ref) { } int main() { mutate(three()); return 0; } ``` You can see I am passing three() to mutate method. This code compiles well. My understanding is, temporaries can't be assigned to non-const references. If yes, how this program is compiling? Any thoughts? Edit: Compilers tried : VS 2008 and VS2010 Beta

Original source