[Cxx-abi-dev] [cxx-abi-dev] Mangling 'this' in trailing-return-type
Mike Herrick
mjh at edg.com
Mon Sep 19 17:45:31 UTC 2011
On Jul 4, 2011, at 10:32 AM, Jason Merrill wrote:
> On 07/01/2011 11:44 PM, Jason Merrill wrote:
>> Since DR 1207, we need to have a representation for uses of 'this' in a
>> trailing-return-type. Perhaps "fpT"?
>
> So,
>
> struct B
> {
> template <class U> U f();
> };
>
> struct A
> {
> B b;
> // implicitly rewritten to (*this).b.f<U>()
> // _ZN1A1fIiEEDTcldtdtdefpT1b1fIT_EEEv
> template <class U> auto f() -> decltype (b.f<U>());
> // _ZN1A1gIiEEDTcldtptfpT1b1fIT_EEEv
> template <class U> auto g() -> decltype (this->b.f<U>());
> };
>
> int main()
> {
> A a;
> a.f<int>();
> a.g<int>();
> }
[Apologies for not responding to this earlier.]
"fpT" seems fine for explicit use of "this" in a trailing-return-type.
We're wondering about the implicit case. Generally, our mangling mantra for SFINAE has been to make the mangled name match the source as closely as possible, so we produce _ZN1A1fIiEEDTcldt1b1fIT_EEEv (which demangles as "decltype(((b.f<T1>)())) A::f<int>()") as a mangled name for the first case above. [EDG happens to use "this->" internally rather than "(*this).".]
Irrespective of the choice of mangling for the implicit case, what are your thoughts on a case like this:
// file 1:
struct B {
template <class U> U f();
};
struct A {
B b;
template <class U> auto f() -> decltype (b.f<U>()) { return 0; }
};
A a;
auto x = a.f<int>();
// file 2:
struct B {
template <class U> U f();
};
struct A {
B b;
template <class U> auto f() -> decltype (this->b.f<U>());
};
extern A a;
int main() {
a.f<int>();
}
We think the implicit and explicit cases should have different manglings even if, from a SFINAE standpoint, they're treated the same, and have a preference for the "mangled as written" implicit mangling.
Mike.
More information about the cxx-abi-dev
mailing list