Bug 2294

Summary: using declaration confusion
Product: gcc Reporter: theonetruekenny
Component: c++Assignee: Giovanni Bajo <giovannibajo>
Status: RESOLVED FIXED    
Severity: normal CC: gcc-bugs, lerdsuwa, pinskia, reichelt
Priority: P3 Keywords: monitored, patch, rejects-valid
Version: 3.0   
Target Milestone: 3.3.3   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2003-11-10 11:18:13

Description theonetruekenny 2001-03-15 12:56:00 UTC
From the example in section 7.3.3 12 of the 1997 draft,
gcc complains about the "using C::f" declaration.

Release:
gcc version 3.0 20010313 (prerelease)

Environment:
online compiler

How-To-Repeat:
from http://anubis.dkuug.dk/jtc1/sc22/open/n2356/dcl.html:
namespace B {
        void f(int);
        void f(double);
}
namespace C {
        void f(int);
        void f(double);
        void f(char);
}
void h()
{
        using B::f;   // B::f(int) and B::f(double)
        using C::f;   // C::f(int), C::f(double), and C::f(char)
        f('h');       // calls C::f(char)
        f(1);         // error: ambiguous: B::f(int) or C::f(int) ?
        void f(int);  // error:
                      // f(int) conflicts with C::f(int) and B::f(int)
}
Comment 1 Kriang Lerdsuwanakij 2001-03-30 02:57:12 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirm as a bug.
Comment 2 Kriang Lerdsuwanakij 2001-03-30 07:57:13 UTC
From: lerdsuwa@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org, nobody@gcc.gnu.org, theonetruekenny@yahoo.com
Cc:  
Subject: Re: c++/2294
Date: 30 Mar 2001 07:57:13 -0000

 Synopsis: using declaration confusion
 
 State-Changed-From-To: open->analyzed
 State-Changed-By: lerdsuwa
 State-Changed-When: Fri Mar 30 02:57:12 2001
 State-Changed-Why:
     Confirm as a bug.
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view&pr=2294&database=gcc

Comment 3 Nathanael C. Nerode 2003-01-01 08:11:25 UTC
From: Nathanael Nerode <neroden@twcny.rr.com>
To: gcc-gnats@gcc.gnu.org, theonetruekenny@yahoo.com, gcc-bugs@gcc.gnu.org,
   nobody@gcc.gnu.org
Cc:  
Subject: Re: c++/2294
Date: Wed, 1 Jan 2003 08:11:25 -0500

 Confirmed still present in mainline as of 2003-01-01, after new parser merge. 
 The second 'using' declaration generates this error: 
 
 error: `f' is already declared in this scope
Comment 4 Giovanni Bajo 2003-10-29 20:20:24 UTC
Patch submitted:
http://gcc.gnu.org/ml/gcc-patches/2003-10/msg02572.html
Comment 5 Kriang Lerdsuwanakij 2003-11-05 14:14:43 UTC
Updated patch from Giovanni Bajo:

  http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00067.html
Comment 6 Giovanni Bajo 2003-11-14 09:06:58 UTC
The patch has been approved for both mainline and 3.3 branch.

See:
http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00652.html
http://gcc.gnu.org/ml/gcc-patches/2003-11/msg00667.html

Bernardo will soon commit the mainline patch to CVS on my behalf, but I will 
keep the PR open until the 3.3 backport is ready (in a few days).
Comment 7 GCC Commits 2003-11-14 20:14:12 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bernie@gcc.gnu.org	2003-11-14 20:14:09

Modified files:
	gcc/cp         : ChangeLog name-lookup.c 

Log message:
	PR c++/2294
	* name-lookup.c (push_overloaded_decl): Always construct an OVERLOAD
	unless the declaration is a built-in.
	(set_namespace_binding): While binding OVERLOADs with only one
	declaration, we still need to call supplement_binding.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3761&r2=1.3762
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.20&r2=1.21

Comment 8 GCC Commits 2003-11-14 20:41:07 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bernie@gcc.gnu.org	2003-11-14 20:41:04

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: using9.C 

Log message:
	PR c++/2294
	* g++.dg/lookup/using9.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3194&r2=1.3195
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/using9.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 9 GCC Commits 2003-11-15 19:35:02 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	bernie@gcc.gnu.org	2003-11-15 19:34:57

Modified files:
	gcc/cp         : ChangeLog name-lookup.c 

Log message:
	PR c++/2294
	* name-lookup.c: Revert previous patch for PR c++/2294 to prevent
	build failure on libjava.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3762&r2=1.3763
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.21&r2=1.22

Comment 10 Giovanni Bajo 2003-11-19 23:51:09 UTC
Patch was reverted because it was breaking libgcj bootstrap. I'm working on the 
new patch.
Comment 11 Giovanni Bajo 2003-11-25 17:57:23 UTC
Patch take 2 posted here:
http://gcc.gnu.org/ml/gcc-patches/2003-11/msg01725.html
Comment 12 GCC Commits 2003-12-07 15:23:34 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	giovannibajo@gcc.gnu.org	2003-12-07 15:23:31

Modified files:
	gcc/cp         : ChangeLog name-lookup.c init.c except.c 

Log message:
	PR c++/2294
	* name-lookup.c (push_overloaded_decl): Always construct an
	OVERLOAD unless the declaration is a built-in.
	(set_namespace_binding): While binding OVERLOADs with only one
	declaration, we still need to call supplement_binding.
	* init.c (build_new_1): Deal with an OVERLOAD set when
	looking up for _Jv_AllocObject.
	* except.c (build_throw): Likewise for _Jv_Throw.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3786&r2=1.3787
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.22&r2=1.23
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/init.c.diff?cvsroot=gcc&r1=1.348&r2=1.349
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/except.c.diff?cvsroot=gcc&r1=1.160&r2=1.161

Comment 13 Giovanni Bajo 2003-12-07 15:28:38 UTC
Revised patch: http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00675.html
Approval: http://gcc.gnu.org/ml/gcc-patches/2003-12/msg00686.html.

I'll prepare and commit a 3.3 backport (requested by Gaby) in a few days, when 
I'm sure the patch is stable. I'll keep the bug open until the 3.3 patch goes 
in as well.
Comment 15 GCC Commits 2003-12-16 04:00:06 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	giovannibajo@gcc.gnu.org	2003-12-16 04:00:01

Modified files:
	gcc/cp         : ChangeLog name-lookup.c 

Log message:
	PR c++/2294
	* name-lookup.c (push_overloaded_decl): always construct an OVERLOAD
	if the declaration comes from an using declaration.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.3807&r2=1.3808
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/name-lookup.c.diff?cvsroot=gcc&r1=1.25&r2=1.26

Comment 16 Andrew Pinski 2003-12-16 19:03:59 UTC
Fixed for 3.4.
Comment 17 GCC Commits 2003-12-27 00:06:03 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	giovannibajo@gcc.gnu.org	2003-12-27 00:05:57

Modified files:
	gcc/cp         : ChangeLog decl.c 

Log message:
	Backport from mainline.
	
	2003-12-16  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR c++/2294
	* decl.c (push_overloaded_decl): always construct an OVERLOAD
	if the declaration comes from an using declaration.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.3076.2.229&r2=1.3076.2.230
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.965.2.66&r2=1.965.2.67

Comment 18 GCC Commits 2003-12-27 00:30:17 UTC
Subject: Bug 2294

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	giovannibajo@gcc.gnu.org	2003-12-27 00:30:14

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/lookup: using9.C 

Log message:
	Backport from mainline:
	2003-11-14  Giovanni Bajo  <giovannibajo@gcc.gnu.org>
	
	PR c++/2294
	* g++.dg/lookup/using9.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.2261.2.345&r2=1.2261.2.346
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/lookup/using9.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.1.12.1

Comment 19 Giovanni Bajo 2003-12-27 00:31:32 UTC
The fix has been backported to the 3.3 branch. This bug is now fixed for any 
version of GCC since 3.3.3. Thanks!