Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mangling for types that are instantiation-dependent but not dependent #114

Open
zygoloid opened this issue Dec 18, 2020 · 2 comments
Open

Comments

@zygoloid
Copy link
Contributor

Testcase:

template<typename T> using void_t = void;
template<typename T> void f(decltype(void_t<T*>(), 1)) {}
template void f<int*>(int);

GCC, Clang, and ICC agree that this is mangled as _Z1fIPiEvDTcmcvv_ELi1EE. But that mangling omits the instantiation-dependent T* expression.

We don't seem to have a <type> production to handle this. Presumably the right mangling would be _Z1fIPiEvDTcmcv6void_tIPT_E_ELi1EE, but that would require mangling this instantiation-dependent name for int as a <class-enum-type>.

Similar things happen for:

struct impl { using type = void; };
template<typename T> using alias = impl;
template<typename T> void f(decltype(alias<T*>::type(), 1)) {}
template void f<int*>(int);

... which GCC rejects, ICC mangles as _Z1fIPiEvDTcmcvv_ELi1EE, and Clang currently mangles as _Z1fIPiEvi but will soon mangle the same as ICC.

@rjmccall
Copy link
Collaborator

rjmccall commented Dec 18, 2020

This is really a problem with the mangling of template aliases, I think. The ABI is quite clear that implementations are required to mangle instantiation-dependent types, expressions, template names, etc. syntactically, and as far as I know implementations are generally good about that. The problem is that template aliases don't have to actually use all their template arguments, and so the ABI's rule that uses of template aliases be mangled as their underlying type doesn't necessarily preserve instantiation-dependence.

It seems to me that the fix is to only mangle applications of template aliases as their underlying type when the alias references all of its template arguments and therefore substitution preserves instantiation-dependence.

@zygoloid
Copy link
Contributor Author

CWG1979 looks like it will give us a mechanism to power this: for "simple" alias templates, we can mangle as the substituted result, and for any other alias template we can mangle it as a simple-template-id -- and doing so would be correct because only "simple" alias templates are equivalent to their expansion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants