The following (IMHO valid) code snippet triggers a segfault since GCC 3.4.0: ================================================== template<int> struct A { void foo(); }; struct B { template<int N> friend void A<N>::A::foo(); }; ================================================== x1.cc:8: internal compiler error: Segmentation fault Please submit a full bug report, [etc.] Before the code was accepted.
Confirmed.
The bug here is that the parser is not resolving A<N>::A to A<N>; instead it is treating that as a typename type. Since the qualified name is appearing in a declaration, and since the containing class is a not a class template, we should resolve the qualified name at this point.
Subject: Bug 29020 Author: mmitchel Date: Wed Oct 4 06:53:55 2006 New Revision: 117425 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117425 Log: PR c++/29020 * friend.c (do_friend): Improve comments; add assertion. * parser.c (cp_parser_nested_name_specifier_opt): Resolve typenames for qualified names used in declarations, even when caching qualified name lookup. PR c++/29020 * g++.dg/template/friend48.C: New test. Added: trunk/gcc/testsuite/g++.dg/template/friend48.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/friend.c trunk/gcc/cp/parser.c trunk/gcc/testsuite/ChangeLog
Fixed in 4.2.0.
Mark, you accidentally committed the fix in parser.c with your patch for PR 28506 (rev. 117695) to the 4.1 branch: http://gcc.gnu.org/ml/gcc-cvs/2006-10/msg00361.html So this is now fixed on the 4.1 branch, too. For completeness sake, would you mind committing also the hunk from friend.c and the testcase?
Subject: Bug 29020 Author: mmitchel Date: Tue Oct 24 03:58:40 2006 New Revision: 117994 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=117994 Log: PR c++/29020 * g++.dg/template/friend48.C: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/g++.dg/template/friend48.C Modified: branches/gcc-4_1-branch/gcc/testsuite/ChangeLog
Volker -- Thank you for spotting this. I decided not to backport the friend.c changes because the new asserts might somehow cause a problem. However, I have now added the testcase, after verifying that it passed. Thanks, -- Mark
Fixed in GCC-4.1.2.