Is the following code legal? MSVC 9 and g ++ 4.4 disagree:
struct base { struct derived {}; }; struct derived : base {}; int main() { typedef derived::derived type; return 0; }
MSVC complains, confusing the nested name for the type constructor:
c:\dev>cl test.cpp Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. test.cpp test.cpp(10) : error C2146: syntax error : missing ';' before identifier 'type' test.cpp(10) : error C2761: '{ctor}' : member function redeclaration not allowed test.cpp(10) : error C2065: 'type' : undeclared identifier
So far g ++ does not:
$ g++ --version test.cpp g++ (Ubuntu/Linaro 4.4.4-14ubuntu5) 4.4.5 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
In context, my code contains a pointer
iterator. To provide an iterator interface, it provides a nested pointer
type, which is a synonym for itself.
source share