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

New mangling rule for deduced default template arguments. #184

Open
mizvekov opened this issue Jun 10, 2024 · 4 comments
Open

New mangling rule for deduced default template arguments. #184

mizvekov opened this issue Jun 10, 2024 · 4 comments

Comments

@mizvekov
Copy link

As part of https://isocpp.org/files/papers/P3310R0.html, we would like to introduce deduction of default template arguments.

When deducing a template template parameter from a template specialization, we propose to default any extra arguments the parameter side would not consume, thus effectively allowing a template template parameter to bind to a template declaration with less template parameters, even if the extra parameters aren't declared as defaulted in the template declaration.

Consider:

template<class T, class U> struct A {};
A<int, float> v;
template<template<class> class TT> void f(TT<int>);

// OK: TT picks 'float' as the default argument for the second parameter.
void g() { f(v); }

Since 'f' specialized from A<int, float> is different from 'f' specialized from A<int, double>, this will affect mangling and so we need new rules.

This should only affect template template arguments.

A class template specialization A<int, double> which was specialized as written, is still the same class when specialized from a template template parameter bound to A deduced from a different specialization.

I would like guidance with such a rule.

My initial idea would be that when mangling such a template template argument, we follow the template name with a number, which is a starting position from which the first argument is deduced, followed by the same mangling we currently use for a template argument list.

Thus:

template<class T, class U> struct A {};

template<template<class> class TT> void f(TT<int>);

void z() {
  f(A<int, double>());
}

This 'f' specialized with A<int, double> would be mangled as _Z1fITtTyE1A1IdEEvT_IiE.

@rjmccall
Copy link
Collaborator

rjmccall commented Jun 12, 2024

Mangling an adjustment on the template argument seems like the right approach. That particular suggestion seems likely to cause problems because of how it separates the template-name from the template-arguments and just drops an arbitrary numeral into the mangling, but we can surely come up with something. I believe we already specify an adjustment for changing template signatures for template template arguments; it's possible that that would be sufficient here, or maybe we need to be more explicit about the deduction.

@mizvekov
Copy link
Author

I believe we already specify an adjustment for changing template signatures for template template arguments; it's possible that that would be sufficient here, or maybe we need to be more explicit about the deduction.

Is this about #166, wrt the template-param-decl production?

@rjmccall
Copy link
Collaborator

Yes. Thanks for reminding me that I need to put some effort into landing that in the spec.

@mizvekov
Copy link
Author

It seems that could work, but it needs to be extended to encode default arguments as well.

Though it seems this could already be required for the proposed resolution of https://open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1286

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