The following code fails to compile on GCC 4.3.3. It compiles on Intel C++ 11.1 and Comeau 4.3.10.1.
g++ -v -save-temps main.cpp Using built-in specs. Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.3.3-5ubuntu4' --with-bugurl=file:///usr/share/doc/gcc-4.3/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --enable-shared --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --enable-nls --with-gxx-include-dir=/usr/include/c++/4.3 --program-suffix=-4.3 --enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 4.3.3 (Ubuntu 4.3.3-5ubuntu4) COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.3.3/cc1plus -E -quiet -v -D_GNU_SOURCE main.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -fpch-preprocess -o main.ii ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/4.3.3/../../../../x86_64-linux-gnu/include" ignoring nonexistent directory "/usr/include/x86_64-linux-gnu" #include "..." search starts here: #include <...> search starts here: /usr/include/c++/4.3 /usr/include/c++/4.3/x86_64-linux-gnu /usr/include/c++/4.3/backward /usr/local/include /usr/lib/gcc/x86_64-linux-gnu/4.3.3/include /usr/lib/gcc/x86_64-linux-gnu/4.3.3/include-fixed /usr/include End of search list. COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic' /usr/lib/gcc/x86_64-linux-gnu/4.3.3/cc1plus -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -auxbase main -version -fstack-protector -o main.s GNU C++ (Ubuntu 4.3.3-5ubuntu4) version 4.3.3 (x86_64-linux-gnu) compiled by GNU C version 4.3.3, GMP version 4.2.4, MPFR version 2.4.0. GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072 Compiler executable checksum: d9dd67dcc191271ac69fd2c05266cf9c main.cpp:22: error: expected identifier before ; token main.cpp:22: error: friend declaration does not name a class or function main.cpp: In member function T Base<T>::InnerBase<D>::baseImpl() [with D = Derived<int>::InnerDerived, T = int]: main.cpp:27: instantiated from T Derived<T>::InnerDerived::operation() [with T = int] main.cpp:45: instantiated from here main.cpp:31: error: T Derived<T>::InnerDerived::derivedHelper() [with T = int] is private main.cpp:11: error: within this context main.cpp: template <class T> class Base { protected: template <class D> class InnerBase { protected: T baseImpl() { return static_cast<D*>(this)->derivedHelper(); } }; }; template <class T> class Derived : public Base<T> { public: class InnerDerived : public Base<T>::template InnerBase<InnerDerived> { friend class Base<T>::template InnerBase<InnerDerived>; // <--- error: expected identifier before ; token public: T operation() { return this->baseImpl(); } private: T derivedHelper() { return T(42); } }; InnerDerived makeInner() const { return InnerDerived(); } }; int main(int argc, char* argv[]) { return Derived<int>().makeInner().operation(); } -- Summary: Parse error declaring friend class using dependent template instance Product: gcc Version: 4.3.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: trevor at scurrilous dot com GCC build triplet: x86_64-linux-gnu GCC host triplet: x86_64-linux-gnu GCC target triplet: x86_64-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40664