public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31986] New: conversion-type-id should match in both contexts
@ 2007-05-18 13:38 andrew dot stubbs at st dot com
2007-05-18 13:54 ` [Bug c++/31986] " andrew dot stubbs at st dot com
0 siblings, 1 reply; 2+ messages in thread
From: andrew dot stubbs at st dot com @ 2007-05-18 13:38 UTC (permalink / raw)
To: gcc-bugs
The following C++ program should not compile:
#include <stdio.h>
class C
{
public:
typedef float T;
operator T() {return 1;};
operator int() {return 2;};
} c;
int
main ()
{
typedef int T;
printf ("%d\n", (T) c.operator T()); // invalid
printf ("%d\n", T(c));
printf ("%d\n", (T)c);
}
The C++ standard, clause 3.4.5, paragraph 7, says that the `T' should refer to
the same type in both `C' and `main'.
The output from this program, with GCC 4.1.1, is "1 2 2" (i.e. a `float' and
two `int's). This shows that the name `T' is significant here.
--
Summary: conversion-type-id should match in both contexts
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=31986
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/31986] conversion-type-id should match in both contexts
2007-05-18 13:38 [Bug c++/31986] New: conversion-type-id should match in both contexts andrew dot stubbs at st dot com
@ 2007-05-18 13:54 ` andrew dot stubbs at st dot com
0 siblings, 0 replies; 2+ messages in thread
From: andrew dot stubbs at st dot com @ 2007-05-18 13:54 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from andrew dot stubbs at st dot com 2007-05-18 14:54 -------
EDG version 3.8 gives the warning:
t.cpp", line 15: warning:
ambiguous class member reference -- type "T" (declared at line 14)
used in preference to type "C::T" (declared at line 6)
printf ("%d\n", (T) c.operator T()); // invalid
^
In contrast to GCC, this gives the output "2 2 2", not "1 2 2".
And in -strict mode (full standard conformance) gives the error:
t.cpp", line 15: error:
ambiguous class member reference -- type "T" (declared at line 14)
used in preference to type "C::T" (declared at line 6)
printf ("%d\n", (T) c.operator T()); // invalid
^
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31986
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-05-18 13:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-18 13:38 [Bug c++/31986] New: conversion-type-id should match in both contexts andrew dot stubbs at st dot com
2007-05-18 13:54 ` [Bug c++/31986] " andrew dot stubbs at st dot com
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).