[cxx-abi-dev] A mangling ambiguity
Martin v. Löwis
loewis at informatik.hu-berlin.de
Sat Dec 7 11:23:29 UTC 2002
"J. Stephen Adamczyk" <jsa at edg.com> writes:
> template <class T> struct A {
> template <class U> operator U() { return 0; }
> };
> int main() {
> A<float> a;
> int i = a;
> }
>
> At the indicated point, the result type of the conversion function ("T_")
> should end, and the template argument list that follows ("IiE") should
> apply to the conversion function itself, not to its return type.
> There's no way for a demangler to know that
Why not? If this were a template argument to the conversion-type-id,
there would have to be another template argument list, which specifies
the conversion operator's template arguments, e.g. something like
template <class T> struct A {
template <class U> operator U() { return sizeof(U); }
};
template <class T> struct B {
template <template<class U>class X> operator X<double>() { return X<double>(); }
};
int main() {
A<double> a;
B<long> b;
a = b;
}
Unfortunately, I can't try this out, since g++ rejects it. But I
believe the mangled name should be something like
_ZN1BIlEcvT_IdEI1AEEv
> This is illustrated by what the g++ demangler does with this name:
>
> A<float>::operator float<int>()
>
> This seems like a genuine ambiguity. Or does someone see an out I'm
> missing?
The demangler is just confused: It doesn't recognise that it hasn't
even seen the template argument list, yet, when demangling the
T_. Instead, it should delay outputting the conversion-function-id
until it has the complete identifier (including its final template
argument list).
For that matter, it appears g++ is also confused. It compiles the
program
#include <stdio.h>
template <class T> struct A {
template <class U> operator U() { return sizeof(U); }
};
int main() {
A<double> a;
int x = a.A<double>::operator int();
double y = a.A<double>::operator double();
int z = a.A<double>::operator double<int>();
printf("%d %f %d\n", x, y, z);
}
Somebody please correct me if I'm wrong: A<double>::operator
double<int> is not a valid conversion-function-id in this case, is it?
Regards,
Martin
More information about the cxx-abi-dev
mailing list