This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Earl Chew wrote: > Is there a recent (3.4.2 or later) patch for the following problem? > > Consider the short program fragment below. There are two failures, and > one success under gcc. > > The entire fragment compiles ok with the latest Microsoft Visual Studio > and even one version before that. > > With gcc 3.4.1 (Cygwin) and gcc 3.4.2, I obtain error messages like: > > ambig.cpp: In function `bool fail1(const X&)': > ambig.cpp:16: error: ambiguous overload for 'operator==' in 'x == 4660' > ambig.cpp:16: note: candidates are: operator==(int, int) <built-in> > ambig.cpp:5: note: bool operator==(short unsigned int, const C&) > ambig.cpp: In function `bool fail2(const X&)': > ambig.cpp:21: error: ambiguous overload for 'operator==' in 'x == 4660u' > ambig.cpp:21: note: candidates are: operator==(int, int) <built-in> > ambig.cpp:5: note: bool operator==(short unsigned int, const C&) > > It seems the compiler will not prefer the conversion from X to > unsigned short in order to compile the (subsequent unsigned short to > unsigned short) comparison and considers the competing conversions > to C as viable. > > Earl Chew > > ------------------------------------------------------------------------------- > > > class C > { > public: > C(unsigned short); > friend bool operator==(unsigned short, const C&); > }; > > class X > { > public: > operator unsigned short() const; > }; > > bool fail1(const X& x) > { > return x == 0x1234; > } > > bool fail2(const X& x) > { > return x == (unsigned short) 0x1234; > } > > bool succeeds(const X& x) > { > return (unsigned short) x == 0x1234; > } > GCC 4.1 compiles it. Cygwin's GCC is a bit old. -- VH
Attachment:
signature.asc
Description: OpenPGP digital signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |