Testcase: unsigned count() { class QGListIterator { friend class QGList; QGListIterator( const QGList & ); }; } -------- I think this is valid code.
The ICE: t2.cc: In function 'unsigned int count()': t2.cc:4: internal compiler error: in lookup_name_real, at cp/name-lookup.c:4014 Please submit a full bug report, with preprocessed source if appropriate. See <URL:http://gcc.gnu.org/bugs.html> for instructions.
I take back this being valid code, to make it valid add "class QGList;" before the function. You still end up with an ICE so this is still a bug. This worked with "4.1.0 20051026" so it is at least a 4.3.0 regression.
This is a regression on the 4.1 branch. For reference, the valid testcase is class QGList; unsigned count() { class QGListIterator { friend class QGList; QGListIterator( const QGList & ); }; }
Subject: Bug number PR c++/30917 A patch for this bug has been added to the patch tracker. The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-03/msg00463.html
Simon -- It took me a while to decide that this patch was OK -- but it is. :-) I will suggest a few changes to make it more obviously correct. First, minor coding style nit: drop the else after the return that you've introduced. Second, we need some chapter-and-verse in here. Please avoid references like "11.4.8" as the numbers tend to move around as the standard changes. (For example, I don't think 11.4.8 is the right reference in either the published standard or the current WP.) For the comment on the gcc_asert, I would say: /* A non namespace-scope binding can only be hidden if we are in a local class, due to friend declarations. In particular, consider: void f() { struct A { friend struct B; void g() { B* b; } // error: B is hidden } struct B {}; } The standard says that "B" is a local class in "f" (but not nested within "A") -- but that name lookup for "B" does not find this declaration until it is declared directly with "f". In particular: [class.friend] If a friend declaration appears in a local class and the name specified is an unqualified name, a prior declaration is looked up without considering scopes that are outside the innermost enclosing non-class scope.... For a friend class declaration, if there is no prior declaration, the class that is specified belongs to the innermost enclosing non-class scope, but if it is subsequently referenced, its name is not found by name lookup until a matching declaration is provided in the innermost enclosing nonclass scope. */ OK with that change. Thanks, -- Mark
Subject: Bug 30917 Author: simartin Date: Sat Jul 28 10:48:30 2007 New Revision: 127016 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127016 Log: gcc/cp/ 2007-07-28 Simon Martin <simartin@users.sourceforge.net> Mark Mitchell <mark@codesourcery.com> PR c++/30917 * name-lookup.c (lookup_name_real): Non namespace-scope bindings can be hidden due to friend declarations in local classes. gcc/testsuite/ 2007-07-28 Simon Martin <simartin@users.sourceforge.net> PR c++/30917 * g++.dg/lookup/friend11.C: New test. Added: trunk/gcc/testsuite/g++.dg/lookup/friend11.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/name-lookup.c trunk/gcc/testsuite/ChangeLog
Subject: Bug 30917 Author: simartin Date: Sat Jul 28 20:12:42 2007 New Revision: 127023 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=127023 Log: gcc/cp/ 2007-07-28 Simon Martin <simartin@users.sourceforge.net> Mark Mitchell <mark@codesourcery.com> PR c++/30917 * name-lookup.c (lookup_name_real): Non namespace-scope bindings can be hidden due to friend declarations in local classes. gcc/testsuite/ 2007-07-28 Simon Martin <simartin@users.sourceforge.net> PR c++/30917 * g++.dg/lookup/friend11.C: New test. Added: branches/gcc-4_2-branch/gcc/testsuite/g++.dg/lookup/friend11.C Modified: branches/gcc-4_2-branch/gcc/cp/ChangeLog branches/gcc-4_2-branch/gcc/cp/name-lookup.c branches/gcc-4_2-branch/gcc/testsuite/ChangeLog
Fixed in 4.2 and 4.3.
Fixed by Simon Martin.