Bug 17585 - [3.4/4.0 Regression] usage of unqualified name of static member from within class not allowed
Summary: [3.4/4.0 Regression] usage of unqualified name of static member from within c...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.2
: P2 normal
Target Milestone: 3.4.3
Assignee: Mark Mitchell
URL:
Keywords: rejects-valid
: 17754 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-09-21 14:48 UTC by tal agmon
Modified: 2005-07-23 22:49 UTC (History)
3 users (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
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 tal agmon 2004-09-21 14:48:43 UTC
Compile the following code with g++ creates the following errors:

template <void (*p)(void)> struct S03 {};
class C03 {
public:
        static void f(void) {}
	void g(void) { S03<&f> s03; }
};

In member function `void C03::g()':
error: missing `>' to terminate the template argument list
error: template argument 1 is invalid
error: expected `;' before "f"
Comment 1 Andrew Pinski 2004-09-21 14:56:00 UTC
Doing 03<(&f)> s03; or 03<f> s03; instead I get:
t.cc:6: error: `static void C03::f()' cannot appear in a constant-expression
t.cc:6: error: `&' cannot appear in a constant-expression
t.cc:6: error: template argument 1 is invalid
t.cc:6: error: invalid type in declaration before ';' token

So this is actually invalid code.
Comment 2 tal agmon 2004-09-21 15:03:50 UTC
From the ANSI-C++ chapter 9.4 Static members:

"A static member s of class X may be referred to using the qualified id
expression X::s; it is not necessary to use the class member access syntax 
(5.2.5) to refer to a static member."
"A static member may be referred to directly in the scope of its class or in 
the scope of a class derived (clause 10) from its class"
Comment 3 Wolfgang Bangerth 2004-09-21 18:56:40 UTC
The correct syntax is 
        void g(void) { S03<&C03::f> s03; } 
With that it compiles cleanly. 
 
W. 
Comment 4 tal agmon 2004-09-22 07:22:40 UTC
According to my quotes from the ANSI-C++ the following syntax is valid:
void g(void) { S03<&f> s03; }

However, the compiler issues errors.
If someone thinks that this is an invalid code, please provide some proof.

Comment 5 Giovanni Bajo 2004-09-22 08:43:52 UTC
I won't confirm it right now, but Tal is right: the standard my not appear 
clear but the syntax &A::f is used to form pointers to members: a pointer to a 
static member function is not a pointer to member, it is a regulard pointer to 
function. [conv.func]/1 (footnote 50) says that "&f" is forbidden for non-
static member function, and it implies that "f" is a regular lvalue for a 
static member function.
Comment 6 Mark Mitchell 2004-09-24 23:13:33 UTC
Working on a fix.
Comment 7 GCC Commits 2004-09-27 14:47:14 UTC
Subject: Bug 17585

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-09-27 14:46:56

Modified files:
	gcc/cp         : ChangeLog semantics.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/template: static8.C 

Log message:
	PR c++/17585
	* semantics.c (finish_id_expression): Do not add "this->" to
	static member functions.
	
	PR c++/17585
	* g++.dg/template/static8.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4387&r2=1.4388
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.438&r2=1.439
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4356&r2=1.4357
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static8.C.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 8 GCC Commits 2004-09-27 18:47:37 UTC
Subject: Bug 17585

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-09-27 18:47:30

Modified files:
	gcc/cp         : ChangeLog cp-tree.h search.c semantics.c 

Log message:
	PR c++/17585
	* cp-tree.h (shared_member_p): Declare.
	* search.c (shared_member_p): Give it external linkage.
	* semantics.c (finish_qualified_id_expr): Use it.
	(finish_id_expression): Likewise.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4388&r2=1.4389
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&r1=1.1053&r2=1.1054
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&r1=1.323&r2=1.324
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&r1=1.439&r2=1.440

Comment 9 GCC Commits 2004-09-27 18:50:26 UTC
Subject: Bug 17585

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-09-27 18:50:24

Modified files:
	gcc/cp         : ChangeLog cp-tree.h search.c semantics.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/parse: error18.C 
	gcc/testsuite/g++.dg/template: static8.C 

Log message:
	PR c++/17585
	* cp-tree.h (shared_member_p): Declare.
	* search.c (shared_member_p): Give it external linkage.
	* semantics.c (finish_qualified_id_expr): Use it.
	(finish_id_expression): Likewise.
	
	PR c++/17585
	* g++.dg/template/static8.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.160&r2=1.3892.2.161
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-tree.h.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.946.4.15&r2=1.946.4.16
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/search.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.284.4.4&r2=1.284.4.5
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.381.4.14&r2=1.381.4.15
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.274&r2=1.3389.2.275
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/parse/error18.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.12.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/template/static8.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 10 Mark Mitchell 2004-09-27 21:14:14 UTC
Fixed in GCC 3.4.3.
Comment 11 Andrew Pinski 2004-09-30 18:02:38 UTC
*** Bug 17754 has been marked as a duplicate of this bug. ***
Comment 12 Ben Hutchings 2004-09-30 18:13:38 UTC
Please change the summary to be more descriptive. I just waste time reporting
the bug again (as 17754) because I couldn't find this report.