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

Fixed wording regarding omitting the template argument list <> CWG2608 #5512

Closed
wants to merge 5 commits into from

Conversation

ranaanoop
Copy link
Contributor

@ranaanoop ranaanoop commented Jun 7, 2022

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.

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.
@jensmaurer
Copy link
Member

jensmaurer commented Jun 7, 2022

Looks good to me.
Note for later: The commit message needs fixing. [temp.arg.explicit]

@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.
source/templates.tex Outdated Show resolved Hide resolved
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>
Copy link
Contributor

@Quuxplusone Quuxplusone left a 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.

source/templates.tex Show resolved Hide resolved
@jensmaurer
Copy link
Member

@Quuxplusone , you said ", only GCC actually implements the example's behavior correctly,"
but the examples in this issue claim that all compilers reject the function pointer case.

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.

@ranaanoop
Copy link
Contributor Author

ranaanoop commented Jun 9, 2022

@jensmaurer As can be seen here all(gcc/clang/msvc) currently reject the statement auto b = f;.

@Quuxplusone
Copy link
Contributor

@jensmaurer As can be seen here all(gcc/clang/msvc) currently reject the statement auto b = f;.

Oh that's fun. It looks like GCC accepts the example auto b = f; only if f<>'s parameter list is composed entirely of non-dependent types. https://godbolt.org/z/EefdTYz6T

@jensmaurer jensmaurer changed the title Fixed wording regarding omitting the template argument list <> Fixed wording regarding omitting the template argument list <> CWG2608 Jul 9, 2022
@jensmaurer
Copy link
Member

I've created CWG2608.

@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Jul 9, 2022
@wg21bot wg21bot added the needs rebase The pull request needs a git rebase to resolve merge conflicts. label Aug 19, 2022
@Mick235711
Copy link
Contributor

Fixed by #5664.

@tkoeppe tkoeppe closed this Aug 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. needs rebase The pull request needs a git rebase to resolve merge conflicts. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants