gcc bug

Matthias Meixner meixner@rbg.informatik.tu-darmstadt.de
Thu Apr 6 23:41:00 GMT 2000


Hello,


I think I have found a bug in gcc (g++). Compiling the following code gives
errors:

-----------------------------------------------------
struct Z { Z(){} };

struct A {
   Z x;

   operator Z *() { return &x; }
   operator const Z *() { return &x; }
   operator const Z *() const { return &x; }
};

struct B {
   Z x;
   
   operator Z &() { return x; }
   operator const Z &() { return x; }
   operator const Z &() const { return x; }
};

main()
{
   A a;
   const A ca;
   Z *a1=a;
   const Z *a2=a;
   const Z *a3=ca;

   B b;
   const B cb;
   Z &b1=b;
   const Z &b2=b;
   const Z &b3=cb;
}
-----------------------------------------------------


> gcc /tmp/t5.cxx
/tmp/t5.cxx: In function `int main()':
/tmp/t5.cxx:30: conversion from `B' to `const Z &' is ambiguous
/tmp/t5.cxx:14: candidates are: B::operator Z &()
/tmp/t5.cxx:15:                 B::operator const Z &()
/tmp/t5.cxx:16:                 B::operator const Z &() const
/tmp/t5.cxx:30: conversion from `B' to `const Z &' is ambiguous
/tmp/t5.cxx:14: candidates are: B::operator Z &()
/tmp/t5.cxx:15:                 B::operator const Z &()
/tmp/t5.cxx:16:                 B::operator const Z &() const

The version of gcc was 2.95.2, system was linux and solaris.

According to my understanding of the C++ standard, there is no ambiguity 
in the code above. Furthermore I have tested another compiler (Sun 
Workshop 5.0) and this compiler does not issue any errors.

Regards,

   Matthias Meixner

-- 
Matthias Meixner                   meixner@rbg.informatik.tu-darmstadt.de
Technische Universität Darmstadt
Rechnerbetriebsgruppe                          Telefon (+49) 6151 16 6670
Wilhelminenstraße 7, D-64283 Darmstadt, Germany    Fax (+49) 6151 16 4701


More information about the Gcc-bugs mailing list