This is the mail archive of the gcc-bugs@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]

Re: G++ bug


Alexandre Oliva wrote:
> 
> On Sep 20, 1999, Andy Rysin <arysin@yahoo.com> wrote:
> 
> > Problem: GCC can not distinct 'typedef unsigned int
> > Rgb' from 'char *' in overloaded constructor when
> > argument is 'Rgb(0)'.
> 
> Try `0u'.  The type of `0' is `int', not `unsigned int'.  Converting
> `int' to `unsigned int' is an integral conversion, and `int' to
> `char*' is a pointer conversion.  Since both are conversions, neither
> is better; overload resolution fails due to ambiguity.

No, I think Andy is right. He's explicitly casting the 0 to QRgb, which
is a typedef for unsigned int; he's not relying on int->unsigned
happening automatically. His code looked like this:

  typedef unsigned int QRgb;
  class QColor {
    public:
      QColor(QRgb rgb, unsigned pixel = 0xffffffff);
      QColor(const char* name);
  };
  class QColorGroup {
    public:
      QColorGroup(const QColor& fg);
  };
  QColorGroup q(QColor(QRgb(1))); // works
  QColorGroup q(QColor(QRgb(0))); // doesn't work

Notice that it only fails when the argument is an explicit zero. The
compiler seems to be taking QRgb(0) to be a null pointer constant, which
is correct so far. *But* the conversion from a null pointer constant to
an actual pointer counts as a "pointer conversion" and has lower rank
than an exact match. (See sections 13.3.3 and 4.10 of the C++ standard.)
So I think this is a genuine bug.

--
Ross Smith <ross.s@ihug.co.nz> The Internet Group, Auckland, New Zealand
========================================================================
  "There are many technical details that make Linux attractive to the
  sort of people to whom technical details are attractive."   -- Suck


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]