mercredi 20 juillet 2016

Is iterator to a container with incomplete data type legal?

Is the following code legal?

class A
{
    std::map<int, A>::iterator x;
};

Visual Studio 2015 accepts it, but clang says

.../ndk/sources/cxx-stl/llvm-libc++/libcxx/include/utility:254:9:  
error: field has incomplete type 'A'
    _T2 second;
    ^
....
a.cpp:52:21:
note: definition of 'A' is not complete until the closing '}'
    struct A
           ^

Edit:
The problem seems to be with the standard library, http://rextester.com/QNNEG57036 fails on it

My question is whether the code is legal or not, not how to fix it (ex. by changing compiler flags).

Aucun commentaire:

Enregistrer un commentaire