should compile, see ISO/IEC 14882:2011 §9.0.2 $ cat test.cpp struct foo { foo::foo::foo::foo::foo::foo* bar; }; $ g++ test.cpp test.cpp:1:14: error: ‘foo::foo’ names the constructor, not the type $ g++ -v Using built-in specs. COLLECT_GCC=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1/g++ COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-pc-linux-gnu/4.7.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /var/tmp/portage/sys-devel/gcc-4.7.1/work/gcc-4.7.1/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/gcc-bin/4.7.1 --includedir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include --datadir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1 --mandir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/man --infodir=/usr/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/info --with-gxx-include-dir=/usr/lib/gcc/x86_64-pc-linux-gnu/4.7.1/include/g++-v4 --host=x86_64-pc-linux-gnu --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-lto --enable-nls --without-included-gettext --with-system-zlib --enable-obsolete --disable-werror --enable-secureplt --enable-multilib --with-multilib-list=m32,m64 --enable-libmudflap --disable-libssp --enable-libgomp --with-python-dir=/share/gcc-data/x86_64-pc-linux-gnu/4.7.1/python --enable-checking=release --disable-libgcj --enable-languages=c,c++,fortran --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-targets=all --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.7.1 p1.0, pie-0.5.3' Thread model: posix gcc version 4.7.1 (Gentoo 4.7.1 p1.0, pie-0.5.3)
This is related to bug 11764 and C++ defect report #147.
My reading of DR 147, makes this invalid code as foo::foo names the constructor.
I would argue that in 3.4.3.1.2 the constructor is not an acceptable lookup result, since it would result in the code being invalid. Additionally, the following use of a type alias (where the constructor is clearly not an acceptable lookup result) does not compile on my g++-4.7.1: struct foo { using bar = foo::foo::foo; };
GCC, clang, ICC and MSVC all say this is not a bug and the name is a constructor name in this context.
This was clarified by Core DR 1310 https://wg21.link/cwg1310 foo::foo names the constructor, and so can only be used to declare the constructor as a friend, or in a using-declaration for inheriting constructors.