Bug 29020 - [4.0 regression] ICE using A<N>::A instead of A<N> in friend declaration
Summary: [4.0 regression] ICE using A<N>::A instead of A<N> in friend declaration
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.2.0
: P1 normal
Target Milestone: 4.1.2
Assignee: Mark Mitchell
URL:
Keywords: ice-on-valid-code, monitored
Depends on: 29535
Blocks:
  Show dependency treegraph
 
Reported: 2006-09-11 19:27 UTC by Volker Reichelt
Modified: 2007-02-03 20:03 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.1.2 4.2.0 4.3.0
Known to fail: 4.1.1
Last reconfirmed: 2006-09-12 05:49:50


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Volker Reichelt 2006-09-11 19:27:59 UTC
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.
Comment 1 Andrew Pinski 2006-09-12 05:49:50 UTC
Confirmed.
Comment 2 Mark Mitchell 2006-10-03 18:35:25 UTC
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.
Comment 3 Mark Mitchell 2006-10-04 06:54:07 UTC
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

Comment 4 Mark Mitchell 2006-10-04 07:03:19 UTC
Fixed in 4.2.0.
Comment 5 Volker Reichelt 2006-10-23 19:32:37 UTC
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?
Comment 6 Mark Mitchell 2006-10-24 03:58:50 UTC
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

Comment 7 Mark Mitchell 2006-10-24 04:06:39 UTC
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
Comment 8 Gabriel Dos Reis 2007-02-03 20:03:14 UTC
Fixed in GCC-4.1.2.