17585 – [3.4/4.0 Regression] usage of unqualified name of static member from within class not allowed (original) (raw)
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 Drea Pinski 2004-09-21 14:56:00 UTC
Doing 03<(&f)> s03; or 03 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 10 Mark Mitchell 2004-09-27 21:14:14 UTC
Fixed in GCC 3.4.3.
Comment 11 Drea 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.