Apparent bug in user defined type conversions
Niall Smart
njs3@doc.ic.ac.uk
Sun May 31 06:42:00 GMT 1998
On May 30, 6:47pm, Alexandre Oliva wrote:
} Subject: Re: Apparent bug in user defined type conversions
[ regarding non-standard conversion from unsigned* to signed* ]
> A diagnostic (like the warning message printed by gcc and egcs) is
> required, but actually rejecting the code or not is up to the compiler
> implementor.
Well, if it is going to provide a non-standard conversion operator then
it should at least be used consistently. If a class has a conversion
operator to unsigned, and is being used where a signed is expected then
the built-in conversion unsigned->signed will be applied. If a class
has a conversion operator to unsigned*, and is used where an signed*
is expected, then the built-in conversion unsigned*->signed* is _not_
applied, this seems inconsistent to me. As a further example consider
this:
class C
{
public:
operator unsigned() { return 0; }
operator unsigned*() { return 0; }
};
void fn1(signed);
void fn2(unsigned);
void fn3(signed*);
void fn4(unsigned*);
void fn5(unsigned float);
int
main()
{
unsigned p;
C c;
fn1(p); // ok: unsigned -> signed
fn2(p); // ok: no conversion required
fn3(&p); // ok: unsigned* -> signed*
fn4(&p); // ok: no conversion required
fn5(p); // ok: unsigned -> unsigned float
fn1(c); // ok: C -> unsigned -> signed
fn2(c); // ok: C -> unsigned
fn3(c); // error: cannot convert c from C to signed*; why not C -> unsigned* -> signed* ?
fn4(c); // ok: C -> unsigned*
fn5(c); // ok: C -> unsigned -> unsigned float
}
Is this the behaviour you would have expected?
Niall
More information about the Gcc-bugs
mailing list