Bug 7176 - g++ confused by friend and static member with same name
g++ confused by friend and static member with same name
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: c++
3.1
: P1 critical
: ---
Assigned To: Not yet assigned to anyone
: rejects-valid
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2002-07-01 04:56 UTC by nmusatti
Modified: 2003-07-25 17:33 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description nmusatti 2002-07-01 04:56:03 UTC
The following preprocessed source should compile without errors, but doesn't:

# 1 "DateTimeNS.cpp"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "DateTimeNS.cpp"
namespace Test {

template <typename Result, typename Value> inline Result convert(Value v) {
    return Result(v);
}

class DateTime {
    friend DateTime Test::convert<DateTime,long>(long);
    static long convert(const long double & v);
};

template <> inline DateTime convert<DateTime,long>(long v) {
        return DateTime();
}

long DateTime::convert(const long double & v) {
        return long(v);
}

}

The error messages are:
DateTimeNS.cpp:9: declaration of `static long int Test::DateTime::convert(const
   long double&)'
DateTimeNS.cpp:3: changes meaning of `convert' from `Result
   Test::convert(Value)'

Release:
GNU C++ version 3.1 (i686-pc-cygwin)

How-To-Repeat:
Save the attached code without the first four lines in a source
file, say a.cpp; run
g++ -c a.cpp
Comment 2 raoulgough 2002-08-03 16:04:12 UTC
From: "Raoul Gough" <RaoulGough@yahoo.co.uk>
To: <gcc-gnats@gcc.gnu.org>,
	<gcc-prs@gcc.gnu.org>,
	<gcc-bugs@gcc.gnu.org>,
	<nobody@gcc.gnu.org>,
	<nmusatti@comm2000.it>
Cc:  
Subject: Re: c++/7176: g++ confused by friend and static member with same name
Date: Sat, 3 Aug 2002 16:04:12 +0100

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 r=7176
 
 Is this PR related to (or the same) as the following much simpler compile
 problem?
 
 typedef int foo;
 
 struct bar {
   foo foo;
 };
 
 $ f:/mingw/bin/g++ -c typename_reuse.cc
 typename_reuse.cc:4: declaration of `foo bar::foo'
 typename_reuse.cc:1: changes meaning of `foo' from `typedef int foo'
 
 BTW, I don't write code like that myself - it's representative of some code
 in the Microsoft DirectX samples.
 
 Regards,
 Raoul Gough.
 
 __________________________________________________
 Do You Yahoo!?
 Everything you'll ever need on one web page
 from News and Sport to Email and Music Charts
 http://uk.my.yahoo.com

Comment 3 nmusatti 2002-08-14 08:26:13 UTC
From: Nicola Musatti <nmusatti@comm2000.it>
To: Raoul Gough <RaoulGough@yahoo.co.uk>
Cc: gcc-gnats@gcc.gnu.org, gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org,
   nobody@gcc.gnu.org
Subject: Re: c++/7176: g++ confused by friend and static member with same name
Date: Wed, 14 Aug 2002 08:26:13 +0200

 Sorry for the delay in answering.
 
 Raoul Gough wrote:
 > 
 > http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&p
 > r=7176
 > 
 > Is this PR related to (or the same) as the following much simpler compile
 > problem?
 > 
 > typedef int foo;
 > 
 > struct bar {
 >   foo foo;
 > };
 > 
 > $ f:/mingw/bin/g++ -c typename_reuse.cc
 > typename_reuse.cc:4: declaration of `foo bar::foo'
 > typename_reuse.cc:1: changes meaning of `foo' from `typedef int foo'
 
 This has many similarities with the problem I submitted, but I don't
 know enough about language details or the compiler to venture an
 opinion.
 
 Cheers,
 Nicola Musatti
 
Comment 4 Gabriel Dos Reis 2002-10-08 14:44:26 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed.  A regression from 2.95
Comment 5 Mark Mitchell 2002-10-14 00:49:04 UTC
State-Changed-From-To: analyzed->closed
State-Changed-Why: Fixed in GCC 3.2.1.
Comment 6 Mark Mitchell 2002-10-14 07:46:30 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7176
Date: 14 Oct 2002 07:46:30 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 00:46:30
 
 Modified files:
 	gcc/cp         : ChangeLog lex.c parse.y 
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.pt: memtemp64.C 
 Added files:
 	gcc/testsuite/g++.dg/parse: friend1.C 
 
 Log message:
 	PR c++/7176
 	* lex.c (do_identifier): Add another option for the parsing
 	parameter.
 	* parse.y (do_id): Use it.
 	
 	PR c++/7176
 	* g++.dg/parse/friend1.C: New test.
 	* g++.old-deja/g++.pt/memtemp64.C: Adjust.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.19&r2=1.2685.2.114.2.20
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.265.2.2&r2=1.265.2.2.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.248.2.5.4.1&r2=1.248.2.5.4.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.23&r2=1.1672.2.166.2.24
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/friend1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.3&r2=1.3.36.1
 

Comment 7 Mark Mitchell 2002-10-14 07:46:30 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7176
Date: 14 Oct 2002 07:46:30 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Branch: 	gcc-3_2-branch
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 00:46:30
 
 Modified files:
 	gcc/cp         : ChangeLog lex.c parse.y 
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.pt: memtemp64.C 
 Added files:
 	gcc/testsuite/g++.dg/parse: friend1.C 
 
 Log message:
 	PR c++/7176
 	* lex.c (do_identifier): Add another option for the parsing
 	parameter.
 	* parse.y (do_id): Use it.
 	
 	PR c++/7176
 	* g++.dg/parse/friend1.C: New test.
 	* g++.old-deja/g++.pt/memtemp64.C: Adjust.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.2685.2.114.2.19&r2=1.2685.2.114.2.20
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.265.2.2&r2=1.265.2.2.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.248.2.5.4.1&r2=1.248.2.5.4.2
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.1672.2.166.2.23&r2=1.1672.2.166.2.24
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/friend1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=NONE&r2=1.1.2.1
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.old-deja/g++.pt/memtemp64.C.diff?cvsroot=gcc&only_with_tag=gcc-3_2-branch&r1=1.3&r2=1.3.36.1
 

Comment 8 Mark Mitchell 2002-10-14 21:09:27 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7176
Date: 14 Oct 2002 21:09:27 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:09:26
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.pt: memtemp64.C 
 	gcc/cp         : ChangeLog lex.c parse.y 
 Added files:
 	gcc/testsuite/g++.dg/parse: friend1.C 
 
 Log message:
 	PR c++/7176
 	* g++.dg/parse/friend1.C: New test.
 	* g++.old-deja/g++.pt/memtemp64.C: Adjust.
 	
 	PR c++/7176
 	* lex.c (do_identifier): Add another option for the parsing
 	parameter.
 	* parse.y (do_id): Use it.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2136&r2=1.2137
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/friend1.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++.pt/memtemp64.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2995&r2=1.2996
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&r1=1.291&r2=1.292
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&r1=1.282&r2=1.283
 

Comment 9 Mark Mitchell 2002-10-14 21:09:27 UTC
From: mmitchel@gcc.gnu.org
To: gcc-gnats@gcc.gnu.org
Cc:  
Subject: c++/7176
Date: 14 Oct 2002 21:09:27 -0000

 CVSROOT:	/cvs/gcc
 Module name:	gcc
 Changes by:	mmitchel@gcc.gnu.org	2002-10-14 14:09:26
 
 Modified files:
 	gcc/testsuite  : ChangeLog 
 	gcc/testsuite/g++.old-deja/g++.pt: memtemp64.C 
 	gcc/cp         : ChangeLog lex.c parse.y 
 Added files:
 	gcc/testsuite/g++.dg/parse: friend1.C 
 
 Log message:
 	PR c++/7176
 	* g++.dg/parse/friend1.C: New test.
 	* g++.old-deja/g++.pt/memtemp64.C: Adjust.
 	
 	PR c++/7176
 	* lex.c (do_identifier): Add another option for the parsing
 	parameter.
 	* parse.y (do_id): Use it.
 
 Patches:
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.2136&r2=1.2137
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/friend1.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++.pt/memtemp64.C.diff?cvsroot=gcc&r1=1.3&r2=1.4
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.2995&r2=1.2996
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/lex.c.diff?cvsroot=gcc&r1=1.291&r2=1.292
 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/parse.y.diff?cvsroot=gcc&r1=1.282&r2=1.283