C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Possible defect in [temp.arg.explicit]'s wording

From: Anoop Rana <ranaanoop986_at_[hidden]>
Date: Wed, 8 Jun 2022 09:13:52 +0530
Re: I noticed that my last reply was sent to only Justin instead to all
users. So sending it again.

I made a pull request last night. Here
<https://github.com/cplusplus/draft/pull/5512> is the link.

On Wed, 8 Jun 2022 at 09:05, Anoop Rana <ranaanoop986_at_[hidden]> wrote:

> I made a pull request last night. Here
> <https://github.com/cplusplus/draft/pull/5512> is the link.
>
> On Wed, 8 Jun 2022 at 02:36, Justin Cooke <jgc_at_[hidden]> wrote:
>
>> This issue was discussed recently on StackOverflow. With Anoop's
>> proposed revised wording for C++20, all three of the following should be
>> valid:
>>
>> template<typename T = int> void func() { }
>> int main()
>> {
>> func(); //#1
>> auto a = func<>; //#2
>> auto b = func; //#3
>> }
>>
>> However, most current compilers accept #1 and #2 but reject #3. It may
>> be appropriate to extend the example in the specification to include these
>> three cases to make clear which of them are intended to be valid.
>>
>> Note that the draft wording for C++23 (13.10.2 in N4910) has been
>> simplified compared with the C++20 standard, but suffers from the same
>> issue.
>>
>> ------------------------------
>>
>> On 7 Jun 2022 at 23:15, Anoop Rana via Std-Proposals wrote:
>>
>> I was reading *temp.arg.explicit*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4> and
>> noticed that there may be some defect in the wording there. In particular,
>> it currently says:
>>
>> *"* * Trailing template arguments that can be * *deduced*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.deduct> * or obtained
>> from default * *template-argument*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument> *s
>> may be omitted from the list of explicit * *template-argument*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.names#nt:template-argument>
>> *s* *.*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-1>
>>
>> *A trailing template parameter pack (* *[temp.variadic]*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.variadic>*) not
>> otherwise deduced will be deduced as an empty sequence of template
>> arguments* *.*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-2>
>>
>> *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* *.*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>
>> *"*
>>
>> *(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 means 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.
>>
>> *Resolution:*
>>
>> The simplest resolution is to change the 3rd sentence quoted above to the
>> following:
>>
>> *If all of the template arguments can be deduced * *or obtained from
>> default template arguments**, they may all be omitted; in this case, the
>> empty template argument list <> itself may also be omitted* *.*
>> <https://timsong-cpp.github.io/cppwp/n4868/temp.arg.explicit#4.sentence-3>
>>
>> *(end resolution)*
>>
>> *I have highlighted the addition/change that i made in the above sentence
>> to make it more clear/easily visible.*
>>
>

Received on 2022-06-08 03:44:05