itanium-cxx-abi / cxx-abi

C++ ABI Summary
507 stars 95 forks source link

Fully specify the mangling of non-type template arguments #166

Open rjmccall opened 1 year ago

rjmccall commented 1 year ago

This includes the material from #47 (non-type template arguments), #63 (class constants), and the template-param-decl portions of #85 (C++20 lambda-expressions).

@zygoloid gets credit for most of this, although I've made a few substantive changes from his suggestions.

zygoloid commented 1 year ago

Something that came up in discussion on #111: what should we do with array-to-pointer decay, in the case where a precise type is not needed? This has been valid since C++98, as an exception to the old general rule that a pointer template parameter couldn't point to a subobject. For example:

int arr[32];
template<int *> struct X {};
void f(X<arr>) {}

GCC mangles this as _Z1f1XIXadL_Z3arrEEE. Clang already implements part of this PR and uses an adsoiL_Z3arrE mangling. But this seems like an avoidable break for GCC: as a very special case, we could instead say that a pointer to the first element of an array is mangled the same as the array itself when precise typing isn't needed and the parameter is not of type cv void *. On the other hand, Clang already took the ABI break here and it seems to not have been problematic, so maybe it's not worth adding a special case.

bolshakov-a commented 1 year ago

Thanks for preparing this! I have some questions inline.

rjmccall commented 5 months ago

Alright, I should take another look at this.