I have the following code on Visual C++ 17 compiler:
#include "stdafx.h"
class Foo {};
Foo FuncBar()
{
return Foo();
}
int main()
{
Foo &myFoo = FuncBar();
}
Normally IIRC, assigning temporaries to lvalues should be illegal. Here I am returning a temporary Foo() and binding it to an lvalue ref. However this code compiles and even runs fine. Why is this allowed?