public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32066] New: member/type lookup doesn't work properly with templates
@ 2007-05-24 10:27 andrew dot stubbs at st dot com
2009-12-07 8:13 ` [Bug c++/32066] " christian dot bruel at st dot com
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: andrew dot stubbs at st dot com @ 2007-05-24 10:27 UTC (permalink / raw)
To: gcc-bugs
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1682 bytes --]
The following is adapted from the example from the C++ standard, clause 14.6/4
(actually it's the updated version from DR345):
1 struct A {
2 struct X { };
3 static int X;
4 } ;
5 template<class T> void f(T t) {
6 typename T::X x; // invalid
7 T::X y; // invalid
8 int z = T::X; // OK
9 }
10 void foo() {
11 A a;
12 f(a); // error: T::X refers to the data member A::X not
13 // the struct A::X.
14 }
I've removed the `B' class from the example, made A::X static (so that T::X may
be used to reference it), and added lines 7 and 8. According to the standard,
clause 14.6/4, all the `T::X' should find the data member X, *not* the type
member X, regardless of the `typename' keyword.
In this case, however, GCC 4.1.1 has not done this, and gives the following
diagnostics:
t.cxx: In function void f(T):
t.cxx:7: error: expected `;' before y
Line 6 has been compiled OK; `T::X' has found the type.
Line 7 has been rejected correctly; `T::X' has not found a type, which means
the `typename' keyword in line 6 was significant.
Line 8 has been compiled correctly; `T::X' has found the data member.
--
Summary: member/type lookup doesn't work properly with templates
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andrew dot stubbs at st dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32066
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/32066] member/type lookup doesn't work properly with templates
2007-05-24 10:27 [Bug c++/32066] New: member/type lookup doesn't work properly with templates andrew dot stubbs at st dot com
@ 2009-12-07 8:13 ` christian dot bruel at st dot com
2009-12-07 15:11 ` redi at gcc dot gnu dot org
2009-12-07 16:41 ` christian dot bruel at st dot com
2 siblings, 0 replies; 6+ messages in thread
From: christian dot bruel at st dot com @ 2009-12-07 8:13 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from christian dot bruel at st dot com 2009-12-07 08:13 -------
I'm wondering if this is not an application of the name hiding rule described
in the IEC 14882:1998 (3.3.7) that says here that the class name T::X is hidden
by the object static int T::X i, so T::X y refers to the object's name not the
class. Making the test invalid. Not certain, just a thought.
This could be reduced as
struct A
{
#ifdef X_MEMBER
static int X;
#endif
#ifdef X_NAME
struct X { };
#endif
} ;
void foo(void)
{
#ifdef X_NAME
A::X y;
#endif
#ifdef X_MEMBER
A::X = 1;
#endif
}
if both X_NAME and X_MEMBER are defined the line A::X y; becomes invalid.
--
christian dot bruel at st dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |christian dot bruel at st
| |dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32066
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/32066] member/type lookup doesn't work properly with templates
2007-05-24 10:27 [Bug c++/32066] New: member/type lookup doesn't work properly with templates andrew dot stubbs at st dot com
2009-12-07 8:13 ` [Bug c++/32066] " christian dot bruel at st dot com
@ 2009-12-07 15:11 ` redi at gcc dot gnu dot org
2009-12-07 16:41 ` christian dot bruel at st dot com
2 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu dot org @ 2009-12-07 15:11 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from redi at gcc dot gnu dot org 2009-12-07 15:11 -------
(In reply to comment #1)
> I'm wondering if this is not an application of the name hiding rule described
> in the IEC 14882:1998 (3.3.7) that says here that the class name T::X is hidden
> by the object static int T::X i, so T::X y refers to the object's name not the
> class.
Exactly. The point is that the standard says "The usual qualified name
lookup (3.4.3) is used to find the qualified-id even in the presence of
typename."
> Making the test invalid. Not certain, just a thought.
The test is supposed to be invalid, but should give an error on line 6 and line
7, GCC only gives an error on line 7.
> This could be reduced as ...
Your reduced version is irrelevant because it's not a template and there's no
"typename" keyword. GCC gets that right, but doesn't get the original report
right.
The test can be reduced to this, which should not compile:
struct A {
struct X { };
int X;
};
template<class T> void f(T t) {
typename T::X x;
}
void foo() {
A a;
f(a); // error: T::X refers to the data member A::X not the struct A::X
}
--
redi at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Ever Confirmed|0 |1
Keywords| |accepts-invalid
Known to fail| |4.1.2 4.4.2
Last reconfirmed|0000-00-00 00:00:00 |2009-12-07 15:11:25
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32066
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/32066] member/type lookup doesn't work properly with templates
2007-05-24 10:27 [Bug c++/32066] New: member/type lookup doesn't work properly with templates andrew dot stubbs at st dot com
2009-12-07 8:13 ` [Bug c++/32066] " christian dot bruel at st dot com
2009-12-07 15:11 ` redi at gcc dot gnu dot org
@ 2009-12-07 16:41 ` christian dot bruel at st dot com
2 siblings, 0 replies; 6+ messages in thread
From: christian dot bruel at st dot com @ 2009-12-07 16:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from christian dot bruel at st dot com 2009-12-07 16:41 -------
> The test can be reduced to this, which should not compile:
>
> struct A {
> struct X { };
> int X;
> };
> template<class T> void f(T t) {
> typename T::X x;
> }
> void foo() {
> A a;
> f(a); // error: T::X refers to the data member A::X not the struct A::X
> }
>
OK. note that with the original tests, 'int X' was declared static.
That makes the case a little bit different since 3.3.7.2 refers to "object,
function or enumerator", not class member.
So variants of this case have declarations:
struct A {
struct X { };
enum x {a, b, c} X;
};
and
struct A {
struct X { };
void X();
};
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32066
^ permalink raw reply [flat|nested] 6+ messages in thread
[parent not found: <bug-32066-4@http.gcc.gnu.org/bugzilla/>]
end of thread, other threads:[~2021-12-09 7:40 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-24 10:27 [Bug c++/32066] New: member/type lookup doesn't work properly with templates andrew dot stubbs at st dot com
2009-12-07 8:13 ` [Bug c++/32066] " christian dot bruel at st dot com
2009-12-07 15:11 ` redi at gcc dot gnu dot org
2009-12-07 16:41 ` christian dot bruel at st dot com
[not found] <bug-32066-4@http.gcc.gnu.org/bugzilla/>
2021-12-09 2:25 ` pinskia at gcc dot gnu.org
2021-12-09 7:40 ` pinskia at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).