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

The standard does not specify when to supply default arguments as template arguments #4082

Closed
xmh0511 opened this issue Jul 14, 2020 · 3 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Jul 14, 2020

template<typename T, typename U = T>
struct Test{};  

template<typename T>
void func(Test<T> /*#1*/){  
}

Consider the above code, at the point of #1, Does the template-id Test<T> require a template argument for corresponding template parameter U? The only quote that mentioned default argument as template argument in the standard is the following :

When a simple-template-id does not name a function, a default template-argument is implicitly instantiated when the value of that default argument is needed. [ Example:
template<typename T, typename U = int> struct S { };
S* p; // the type of p is S<bool, int>*
The default argument for U is instantiated to form the type S<bool, int>*.  — end example ]

However at the point of #1, The specialization of Test<T> is just a part of a function template definition, that is, there's no instantiation occurs here. So, the above quote seems to be not suitable for this case.

In the standard, there's a quote explicitly specified when to supply default arguments as arguments for function call, that is:

If an initializer-clause is specified in a parameter-declaration this initializer-clause is used as a default argument. Default arguments will be used in calls where trailing arguments are missing.

So, Is it necessary to formulate a formally terminology to cover this case? such as

A default template-argument is a template-argument ([temp.arg]) specified after = in a template-parameter. Default arguments will be used in template-id where trailing arguments are missing and the corresponding template parameter does not participate in template argument deduction.

@xmh0511 xmh0511 changed the title The standard does not specify when supply default arguments as template arguments The standard does not specify when to supply default arguments as template arguments Jul 14, 2020
@jensmaurer
Copy link
Member

This was clarified by P1787; [temp.names] p7 now says Test<T> is a valid template-id.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Jan 4, 2021

Sorry, I don't see any mention in P1787 about that, the modification of [temp.names]/P7 is written as the following:

When the template-name of a simple-template-id names a constrained non-function template or a constrained template template-parameter, and all template-argument⁠s in the simple-template-id are non-dependent ([temp.dep.temp]), the associated constraints ([temp.constr.decl]) of the constrained template shall be satisfied ([temp.constr.constr]). [Example:[…]

@JohelEGP
Copy link
Contributor

JohelEGP commented Jan 4, 2021

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

3 participants