On Sun, Sep 02, 2007 at 10:19:27AM +0200, Martin Michlmayr wrote:
> Maybe Ben or Brian can comment.
> 
> * Erik Johansson <[EMAIL PROTECTED]> [2007-09-02 00:39]:
> > Package: gcc-snapshot
> > Version: 20070829-1
> > Severity: normal
> > 
> > The following code compiles with g++ 4.2 but fails with "ISO C++ says
> > that these are ambiguous, even though the worst conversion for the
> > first is better than the worst conversion for the second" when
> > compiling with latest gcc-snapshot. If I remove the QString include it
> > compiles with gcc-snapshot.

This is probably because an incomplete type is used, and also because
one of the below structs is not in scope, therefore making the problem
moot.

> > Below is a simpler example that illustrates the same problem.

I used this one, just because I don't have Qt4-dev installed.

> > struct A {
> >   A(const struct B&) {}
> > };
> > 
> > struct B {
> >   bool operator==(const A&) const { return true; }
> > };
> > 
> > bool operator==(const B&, const B&) {
> >   return false;
> > }
> > 
> > int main()
> > {
> >   if (B() == B())

I can't find anywhere in the standard that makes this explicitly
ambiguous.  In fact, it doesn't appear to be ambiguous at all, because
one doesn't use the conversion and one does.

I *can* tell that the worst conversion for the first (i.e., none) is
better than the worst conversion for the second.  Better ask either Ben
or the GCC people.  The latter would be able to tell you if this is one
of the cases they wrote the warning for.

> >     return 1;
> >   return 0;
> > }
> > 
> > 
> > Is this a regression in gcc or is it something that must be fixed by
> > making A's constructor explicit?

It looks like it might be a regression, but I can't be sure.  If you
want to hedge your bets (and make it clearer for your average
programmer), use "explicit", if that gives the proper semantics.

-- 
brian m. carlson / brian with sandals: Houston, Texas, US
+1 713 440 7475 | http://crustytoothpaste.ath.cx/~bmc | My opinion only
OpenPGP: RSA v4 4096b 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

Attachment: signature.asc
Description: Digital signature

Reply via email to