Consider the code below:
struct Foo {
struct Bar;
Foo()
{
Bar bar; // Why isn't Bar an incomplete type?!
}
struct Bar {}; // Full definition
};
// struct Bar {}; // fails to compile due to incomplete type
int main()
{
Foo foo;
}
It compiles fine under at least 2 compilers (gcc5.2, clang3.5). My question is:
- Why isn't
Bar
considered an incomplete type in the constructorFoo::Foo
, as I forward-declare it above the constructor but fully use it inside the constructor?
Whenever I move Foo::Bar
outside the class, in other words Bar
becomes a stand-alone class, I get the expected
error: aggregate 'Foo::Bar bar' has incomplete type and cannot be defined