Bug 7874 - [3.4/4.0/4.1 regression] g++ finds friend functions defined in class-definition but not declared in the enclosing namespace
Summary: [3.4/4.0/4.1 regression] g++ finds friend functions defined in class-definiti...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.0
: P2 normal
Target Milestone: 4.1.0
Assignee: Kriang Lerdsuwanakij
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: accepts-invalid
: 2949 8280 13917 28681 (view as bug list)
Depends on:
Blocks: 12944 11314 16995
  Show dependency treegraph
 
Reported: 2002-09-09 15:56 UTC by Gabriel Dos Reis
Modified: 2006-08-10 16:03 UTC (History)
11 users (show)

See Also:
Host:
Target:
Build:
Known to work: 2.95.3
Known to fail: 4.0.0 3.4.0
Last reconfirmed: 2005-06-19 04:08:03


Attachments
name-lookup1.C (125 bytes, text/plain)
2003-05-21 15:16 UTC, Gabriel Dos Reis
Details
diffs (548 bytes, application/octet-stream)
2004-01-14 16:55 UTC, Mark Mitchell
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Gabriel Dos Reis 2002-09-09 15:56:01 UTC
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
Comment 1 Gabriel Dos Reis 2002-09-09 19:20:12 UTC
Responsible-Changed-From-To: unassigned->gdr
Responsible-Changed-Why: Working on a patch
Comment 2 Nathan Sidwell 2002-09-13 07:24:40 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: confirmed - Gaby, there are several instances of this PR
    in gnats
Comment 3 pop 2002-10-09 01:47:04 UTC
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)
 

Comment 4 pop 2002-10-09 18:13:08 UTC
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.
Comment 5 Mark Mitchell 2003-07-11 22:36:24 UTC
Postponed until GCC 3.3.2.
Comment 6 Andrew Pinski 2003-07-15 13:16:02 UTC
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.
Comment 7 Mark Mitchell 2003-10-16 02:22:15 UTC
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.
Comment 8 Andrew Pinski 2003-12-28 04:31:19 UTC
*** Bug 8280 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2003-12-28 04:36:37 UTC
*** Bug 2949 has been marked as a duplicate of this bug. ***
Comment 10 Steven Bosscher 2004-01-14 12:54:55 UTC
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 
 
Comment 11 Mark Mitchell 2004-01-14 16:54:58 UTC
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.
>

Comment 12 Mark Mitchell 2004-01-14 16:55:33 UTC
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.
>
Comment 13 Mark Mitchell 2004-01-14 16:55:35 UTC
Created attachment 5482 [details]
diffs
Comment 14 Mark Mitchell 2004-01-14 16:58:57 UTC
Postponed until GCC 3.5, after deprecation has taken effect.
Comment 15 Giovanni Bajo 2004-01-14 17:03:17 UTC
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.
Comment 16 Mark Mitchell 2004-01-14 17:10:26 UTC
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.
>

Comment 17 Andrew Pinski 2004-01-29 06:05:49 UTC
*** Bug 13917 has been marked as a duplicate of this bug. ***
Comment 18 Kriang Lerdsuwanakij 2004-10-17 14:41:18 UTC
Working on friend class name injection.  It's very likely 
the fix also applies to friend function.
Comment 19 Kriang Lerdsuwanakij 2004-11-28 05:38:21 UTC
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.
Comment 20 CVS Commits 2005-09-12 19:54:40 UTC
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

Comment 21 Ian Lance Taylor 2005-09-12 20:10:32 UTC
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.
Comment 22 Andrew Pinski 2006-08-10 16:03:43 UTC
*** Bug 28681 has been marked as a duplicate of this bug. ***