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
Fixed wording regarding omitting the template argument list <> CWG2608 #5512
Conversation
I was reading [temp.arg.explicit] and noticed that there may be some defect in the wording there. In particular, it currently says: " Trailing template arguments that can be deduced or obtained from default template-arguments may be omitted from the list of explicit template-arguments. A trailing template parameter pack ([temp.variadic]) not otherwise deduced will be deduced as an empty sequence of template arguments. If all of the template arguments can be deduced, they may all be omitted; in this case, the empty template argument list <> itself may also be omitted. " (emphasis mine) Note carefully, in the last statement it says that when all of the template arguments can be deduced then they may all be omitted and in this case the empty <> itself may also be omitted. This is an issue because it does not mention that we can also omit the empty <> when all of the template arguments can be obtained from the default template arguments. Since deducing arguments and using default values are two different things, there should be a separate mention of the latter. Only in the first sentence(quoted above) there is a mention of default template arguments but that is only in the context of the list of explicit template arguments. This also means that according to the current wording(sentence 3 quoted above) the following should be invalid: template<typename T = int> void func() { } int main() { func(); //this should be invalid according to the current wording } But we know that the above is not invalid and so there should be changes made to the sentence 3 quoted above to include the case of default template arguments.
Looks good to me. @zygoloid , what do you think? |
After the revised wording at https://github.com/cplusplus/draft/pull/5512/files, all of the following should be valid: template <typename T = int> void f(T) { } int main() { func(); //calls specialization func<int> auto a = func<>; //\tcode{a} has type void (*)(int) auto b = func; //OK: \tcode{b} has type void (*)(int) }
Here a typo made in the example showing when empty<> can be omitted has been fixed.
Added some formatting in description of the example added indicating when empty<> can be omitted Co-authored-by: Johel Ernesto Guerrero Peña <johelegp@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally suggested @ranaanoop submit this as an editorial change; but since it's now been revealed that out of GCC/Clang/MSVC, only GCC actually implements the example's behavior correctly, sadly I now think this is non-editorial and at least a CWG issue if not a full-on paper. I don't think "adding an example, for a long-standing language feature, on which Clang and MSVC currently fail" can possibly be editorial in nature.
@Quuxplusone , you said ", only GCC actually implements the example's behavior correctly," Is there some documentation missing? Could someone please provide a godbolt link with the example (and the result of the major four compilers)? "Implementation divergence" is a strong argument for making this a proper CWG issue. |
@jensmaurer As can be seen here all(gcc/clang/msvc) currently reject the statement |
Oh that's fun. It looks like GCC accepts the example |
I've created CWG2608. |
Fixed by #5664. |
I was reading [temp.arg.explicit] and noticed that there may be some defect in the wording there. In particular, it currently says:
(emphasis mine)
Note carefully, in the last statement it says that when all of the template arguments can be deduced then they may all be omitted and in this case the empty <> itself may also be omitted. This is an issue because it does not mention that we can also omit the empty <> when all of the template arguments can be obtained from the default template arguments. Since deducing arguments and using default values are two different things, there should be a separate mention of the latter.
Only in the first sentence(quoted above) there is a mention of default template arguments but that is only in the context of the list of explicit template arguments.
This also means that according to the current wording(sentence 3 quoted above) the following should be invalid:
But we know that the above is not invalid and so there should be changes made to the sentence 3 quoted above to include the case of default template arguments.