I spent some time looking for a dupe of this bug because it has been around at least since version 3.3.5, and also is in 4.0.0 CVS, but I haven't found one:
I think this is illegal code, though I haven't checked, I put the parts to make it work in comments: template<typename AT> class A{ template<typename BT> class B; }; template<typename AT> template<typename BT> class A<AT>::B{ template<typename BT2> friend class /*A<AT>::*/B; }; segfaults on versions: 4.0.0 20041218 (experimental) 3.4.4 20041218 (prerelease) (Debian 3.4.3-6) 3.3.5 (Debian 1:3.3.5-5) -- Summary: crash on invalid template friend decl Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: sstrasser at systemhaus-gruppe dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19772