Ordinary name lookup rules are wrongly implemented: g++ should not find, by ordinary name lookup rules, friend function names defined in class-definition and not declared in the enclosing namespace. This is a regression from 2.95.x Release: All 3.x series Environment: Plateform independent
Responsible-Changed-From-To: unassigned->gdr Responsible-Changed-Why: Working on a patch
State-Changed-From-To: open->analyzed State-Changed-Why: confirmed - Gaby, there are several instances of this PR in gnats
From: =?iso-8859-1?Q?Pop_S=E9bastian?= <pop@gauvain.u-strasbg.fr> To: nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, gdr@gcc.gnu.org, gdr@nerim.net, gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/7874: g++ finds otherwise names otherwise invisible by ordinary name lookup Date: Wed, 9 Oct 2002 01:47:04 +0200 On Fri, Sep 13, 2002 at 02:24:40PM -0000, nathan@gcc.gnu.org wrote: > Synopsis: g++ finds otherwise names otherwise invisible by ordinary name lookup > > State-Changed-From-To: open->analyzed > State-Changed-By: nathan > State-Changed-When: Fri Sep 13 07:24:40 2002 > State-Changed-Why: > confirmed - Gaby, there are several instances of this PR > in gnats > > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7874 I cannot reproduce this error on gcc version 3.2.1 20020924 (Debian prerelease) version gcc 3.3 20021007 (experimental)
From: =?iso-8859-1?Q?Pop_S=E9bastian?= <pop@gauvain.u-strasbg.fr> To: nathan@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, gdr@gcc.gnu.org, gdr@nerim.net, gcc-gnats@gcc.gnu.org Cc: Subject: Re: c++/7874: g++ finds otherwise names otherwise invisible by ordinary name lookup Date: Wed, 9 Oct 2002 18:13:08 +0200 On Wed, Oct 09, 2002 at 01:47:04AM +0200, Pop Sébastian wrote: > > I cannot reproduce this error on > gcc version 3.2.1 20020924 (Debian prerelease) > version gcc 3.3 20021007 (experimental) > The above is false. In fact we expect that the compiler generates an error as it does on 2.95 Sorry for the confusion, Sebastian.
Postponed until GCC 3.3.2.
Acording to Phil's regression hunter this has been accepted since at least 2000-12-31, so a change before that day caused this regression.
Fixing this requires removing support for ARM-style name-injection. That's fine -- but it's too invasive for a 3.3.x release. Postponed until GCC 3.4.
*** Bug 8280 has been marked as a duplicate of this bug. ***
*** Bug 2949 has been marked as a duplicate of this bug. ***
Mark, You wrote that "[f]ixing this requires removing support for ARM-style name-injection. That's fine -- but it's too invasive for a 3.3.x release. Postponed until GCC 3.4.". Does this mean that we should deprecate this name-injection for 3.4 so that this can be fixed for GCC 3.5? Thanks, Gr. Steven
Subject: Re: [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace Correct you are. I've checked in the attached documentation patch, and I'll change the bug target on that bug. Thanks, -- Mark Mitchell CodeSourcery, LLC mark@codesourcery.com ----- Original Message ----- From: "steven at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: <mark@codesourcery.com> Sent: Wednesday, January 14, 2004 4:55 AM Subject: [Bug c++/7874] [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace > > ------- Additional Comments From steven at gcc dot gnu dot org 2004-01-14 12:54 ------- > Mark, > > You wrote that "[f]ixing this requires removing support for ARM-style > name-injection. That's fine -- but it's too invasive for a 3.3.x release. > Postponed until GCC 3.4.". > > Does this mean that we should deprecate this name-injection for 3.4 so > that this can be fixed for GCC 3.5? > > Thanks, > > Gr. > Steven > > > -- > What |Removed |Added > -------------------------------------------------------------------------- -- > CC| |mark at codesourcery dot com > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7874 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is. >
Subject: Re: [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace And this time, with the patch... -- Mark Mitchell CodeSourcery, LLC mark@codesourcery.com ----- Original Message ----- From: "steven at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org> To: <mark@codesourcery.com> Sent: Wednesday, January 14, 2004 4:55 AM Subject: [Bug c++/7874] [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace > > ------- Additional Comments From steven at gcc dot gnu dot org 2004-01-14 12:54 ------- > Mark, > > You wrote that "[f]ixing this requires removing support for ARM-style > name-injection. That's fine -- but it's too invasive for a 3.3.x release. > Postponed until GCC 3.4.". > > Does this mean that we should deprecate this name-injection for 3.4 so > that this can be fixed for GCC 3.5? > > Thanks, > > Gr. > Steven > > > -- > What |Removed |Added > -------------------------------------------------------------------------- -- > CC| |mark at codesourcery dot com > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7874 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is. >
Created attachment 5482 [details] diffs
Postponed until GCC 3.5, after deprecation has taken effect.
Mark, shouldn't we also emit a warning when trying to compile the deprecated construct? Otherwise, given how many C++ changes we already have for 3.4, we could remove it immediatly.
Subject: Re: [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace We can't remove it immediately because that's not technically easy, and not appropriate for Stage 3. We can't emit warnings because the old warning we would emit would be to warn about every single friend declaration. Thanks, -- Mark Mitchell CodeSourcery, LLC mark@codesourcery.com ----- Original Message ----- From: "giovannibajo at libero dot it" <gcc-bugzilla@gcc.gnu.org> To: <mark@codesourcery.com> Sent: Wednesday, January 14, 2004 9:03 AM Subject: [Bug c++/7874] [3.3/3.4 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace > > ------- Additional Comments From giovannibajo at libero dot it 2004-01-14 17:03 ------- > Mark, shouldn't we also emit a warning when trying to compile the deprecated > construct? Otherwise, given how many C++ changes we already have for 3.4, we > could remove it immediatly. > > -- > > > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=7874 > > ------- You are receiving this mail because: ------- > You are on the CC list for the bug, or are watching someone who is. >
*** Bug 13917 has been marked as a duplicate of this bug. ***
Working on friend class name injection. It's very likely the fix also applies to friend function.
Got a solution for friend class, but not friend function yet. The tough part is the need to look at interaction between hidden friend and hidden built-in functions. Likely postponed to 4.1.
Subject: Bug 7874 CVSROOT: /cvs/gcc Module name: gcc Changes by: ian@gcc.gnu.org 2005-09-12 19:54:23 Modified files: gcc : ChangeLog c.opt gcc/cp : ChangeLog call.c class.c cp-tree.h decl.c friend.c name-lookup.c name-lookup.h pt.c semantics.c gcc/doc : invoke.texi gcc/testsuite : ChangeLog gcc/testsuite/g++.dg/parse: defarg4.C gcc/testsuite/g++.old-deja/g++.brendan: crash56.C gcc/testsuite/g++.old-deja/g++.jason: friend.C scoping15.C gcc/testsuite/g++.old-deja/g++.mike: net43.C Added files: gcc/testsuite/g++.dg/lookup: friend7.C friend8.C Log message: ./ PR g++/7874 * c.opt (ffriend-injection): New C++ option. * doc/invoke.texi (Option Summary): Mention -ffriend-injection. (C++ Dialect Options): Document -ffriend-injection. cp/ PR g++/7874 * cp-tree.h (struct lang_decl_flags): Add hidden_friend_p bitfield. Make dummy bitfield one bit smaller. (DECL_HIDDEN_FRIEND_P): Define. (pushdecl_maybe_friend): Declare. (pushdecl_top_level_maybe_friend): Declare. * decl.c (duplicate_decls): Add newdecl_is_friend parameter. Change prototype and all callers. Add assertion that a DECL_ARTIFICIAL FUNCTION_DECL is not DECL_HIDDEN_FRIEND_P. Set DECL_ANTICIPATED and DECL_HIDDEN_FRIEND_P in duplicated decl if appropriate. * name-lookup.c (supplement_binding): Don't ignore a DECL_HIDDEN_FRIEND_P. (pushdecl_maybe_friend): Break out contents of pushdecl. Add is_friend parameter. Set DECL_ANTICIPATED and DECL_HIDDEN_FRIEND_P for a friend function. (pushdecl): Just call pushdecl_maybe_friend. (pushdecl_with_scope): Add is_friend parameter. Change prototype and all callers. (pushdecl_namespace_level): Likewise. (push_overloaded_decl): Likewise. Check DECL_HIDDEN_FRIEND_P as well as DECL_ANTICIPATED when checking for a builtin. (do_nonmember_using_decl): Check DECL_HIDDEN_FRIEND_P as well as DECL_ANTICIPATED when checking for a builtin. (do_nonmember_using_decl): Likewise. (pushdecl_top_level_1): Add is_friend parameter. Change all callers. (pushdecl_top_level_maybe_friend): New function. (remove_hidden_names): New function. (struct arg_lookup): Add args field. (friend_of_associated_class_p): New static function. (arg_assoc_namespace): Ignore hidden functions which are not friends of an associated class of some argument. (lookup_arg_dependent): Remove hidden functions from list passed in. Initialize k.args. * name-lookup.h (remove_hidden_names): Declare. * friend.c (do_friend): Call pushdecl_maybe_friend instead of pushdecl. * call.c (add_function_candidate): Change DECL_ANTICIPATED test to an assertion, with a check for DECL_HIDDEN_FRIEND_P. (build_new_function_call): Add koenig_p parameter. Change prototype and callers. * pt.c (register_specialization): Add is_friend parameter. Change all callers. (push_template_decl_real): Change is_friend parameter to bool. Change prototype and all callers. (tsubst_friend_class): Call pushdecl_top_level_maybe_friend instead of pushdecl_top_level. testsuite/ PR g++/7874 * g++.dg/lookup/friend7.C: New test. * g++.dg/lookup/friend8.C: New test. * g++.dg/parse/defarg4.C: Add a parameter to the friend function, so that it will be found via argument dependent lookup. * g++.old-deja/g++.brendan/crash56.C: Don't expect errors for friend functions which will no longer be found. * g++.old-deja/g++.jason/friend.C: Add a parameter to the friend function g, so that it will be found via argument dependent lookup. * g++.old-deja/g++.jason/scoping15.C: Use -ffriend-injection. * g++.old-deja/g++.mike/net43.C: Likewise. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.9941&r2=2.9942 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c.opt.diff?cvsroot=gcc&r1=1.50&r2=1.51 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4884&r2=1.4885 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/call.c.diff?cvsroot=gcc&r1=1.551&r2=1.552 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/class.c.diff?cvsroot=gcc&r1=1.731&r2=1.732 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1163&r2=1.1164 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1425&r2=1.1426 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/friend.c.diff?cvsroot=gcc&r1=1.109&r2=1.110 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.140&r2=1.141 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.h.diff?cvsroot=gcc&r1=1.44&r2=1.45 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/pt.c.diff?cvsroot=gcc&r1=1.1031&r2=1.1032 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.489&r2=1.490 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&r1=1.676&r2=1.677 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6049&r2=1.6050 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/friend7.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/friend8.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/defarg4.C.diff?cvsroot=gcc&r1=1.1&r2=1.2 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.brendan/crash56.C.diff?cvsroot=gcc&r1=1.9&r2=1.10 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.jason/friend.C.diff?cvsroot=gcc&r1=1.4&r2=1.5 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.jason/scoping15.C.diff?cvsroot=gcc&r1=1.3&r2=1.4 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.mike/net43.C.diff?cvsroot=gcc&r1=1.4&r2=1.5
Bug is fixed in mainline. The fix will not be migrated back to the 3.4 or 4.0 branches, as it is inappropriate to change default behaviour to stop accepting working programs in a point release.
*** Bug 28681 has been marked as a duplicate of this bug. ***