What happens when a return value from a C ++ function returning a reference of an undefined object type is not assigned?

Consider the following code:

class Foo;

Foo& CreateFoo();


void Bar()
{
   CreateFoo();
}

In Visual Studio, this will cause error C2027 that Foo is of type undefined. In most other compilers, it compiles fine. This is only a problem if the return value of CreateFoo is not assigned. If I changed the line to:

Foo& foo = CreateFoo();

It compiles fine in Visual Studio. Also, if Foo is defined, and not just declared forward, then it will compile fine without assignment.

What should be the right behavior? Is there anything in the C ++ standard that addresses this, or is that what remains of the implementation? I looked and did not see anything that said this.

Update: Error report sent.

+5
2

( 5.2.2):

- lvalue, lvalue rvalue type, xvalue, rvalue prvalue.

prvalue :

    • decltype

    • , decltype,

    prvalue. prvalue . [: prvalue ; , , . (13.3.1.2). - ] [: decltype, , - (7.1.6.2), . - ]

  • prvalue .

lvalue, lvalue, .

, , ++ 11, Visual ++.

+6

( , - ), , .

CreateFoo(); (void) CreateFoo();, , Visual Studio Foo, ( , void), , .

Foo & foo = CreateFoo();, , .

+1

All Articles