C++ Logo

std-discussion

Advanced search

Re: It seems to a wording defect about template argument deduction for function parameter pack

From: jim x <xmh970252187_at_[hidden]>
Date: Fri, 17 Jul 2020 00:59:52 +0800
Hi, Peter. In my first example, the corresponding declarator-id is
<...args>, So the P is T, however I my second example, there's no
declarator-id here, only abstract-declarator-id that denote <...>, but the
rule says that the type of declarator-id is P. so what is the P of T... in
the second example

<std-discussion-request_at_[hidden]> 于 2020年7月16日周四 下午11:34写道:

> Send Std-Discussion mailing list submissions to
> std-discussion_at_[hidden]
>
> To subscribe or unsubscribe via the World Wide Web, visit
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> or, via email, send a message with subject or body 'help' to
> std-discussion-request_at_[hidden]
>
> You can reach the person managing the list at
> std-discussion-owner_at_[hidden]
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Std-Discussion digest..."
>
>
> Today's Topics:
>
> 1. Any progress with P0537? How to proceed? (Deniz Bahadir)
> 2. It seems to a wording defect about template argument
> deduction for function parameter pack (jim x)
> 3. The standard does not specify when to supply default
> arguments as template arguments (jim x)
> 4. Re: It seems to a wording defect about template argument
> deduction for function parameter pack (Peter Sommerlad (C++))
> 5. Re: The standard does not specify when to supply default
> arguments as template arguments (Peter Sommerlad (C++))
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 16 Jul 2020 12:06:16 +0200
> From: Deniz Bahadir <deniz.bahadir_at_[hidden]>
> To: std-discussion_at_[hidden]
> Subject: [std-discussion] Any progress with P0537? How to proceed?
> Message-ID: <e6aa8508-9f5f-9510-115d-6bbd2729e96f_at_[hidden]>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Hello everyone,
>
> I was lately playing around with symbol visibility and C++ attributes in
> Clang and I stumbled over a problem that was described by Matthew
> Woehlke in his proposal paper P0537 ("Allow Attributes on Template
> Explicit Instantiations").
>
> Clang currently does not allow C++ attributes at explicit template
> instantiations [1], because the C++ standard explicitly says that it
> would be illegal.
> However, it would be needed if one wants to make such an explicitly
> instantiated type visible from outside the shared library it is compiled
> in (using C++ attribute syntax).
>
> E.g., the following is not supported by Clang:
>
> ```
> template <typename T>
> T foo(T) { return 0; }
>
> template [[gnu::visibility("default")]]
> int foo<int>(int);
> ```
>
> However, using the compiler-specific syntax is accepted by Clang:
>
> ```
> template <typename T>
> T foo(T) { return 0; }
>
> template __attribute__((gnu::visibility("default")))
> int foo<int>(int);
> ```
>
> By the way, GCC accepts both.
>
> In the associated Clang bug-ticket [1] Matthew mentions his proposal
> P0537 [2] and the result of the EWG poll from 2017 Kona committee
> meeting [3].
>
> There seemed to be consensus that P0537 points out a C++ defect and that
> all compilers should support C++ attributes at explicit template
> instantiations (as does GCC).
>
> However, I was unable to find this mentioned in any C++ defect report.
> In fact, the problematic sentence is still in the latest draft for
> C++20. And Clang still does not support it with the upcoming Clang 11.
>
>
> Does anyone know what is missing to get this into the list of C++
> defects or to remove the problematic sentence from the C++ standard
> entirely? (Who has to proceed how?)
>
>
> Thanks for your insights,
> Deniz Bahadir
>
>
> [1] https://bugs.llvm.org/show_bug.cgi?id=29094
> [2] https://wg21.link/p0537
> [3] https://bugs.llvm.org/show_bug.cgi?id=29094#c5
>
>
> --
> BENOCS GmbH
> Dipl.-Inform. Deniz Bahadir
> Reuchlinstr. 10 D
> 10553 Berlin
> Germany
> Phone: +49 - 30 / 577 0004-22
> Email: deniz.bahadir_at_[hidden]
> www.benocs.com
>
> Board of Management: Stephan Schr?der, Dr.-Ing. Ingmar Poese
> Commercial Register: Amtsgericht Bonn HRB 19378
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 16 Jul 2020 22:28:34 +0800
> From: jim x <xmh970252187_at_[hidden]>
> To: std-discussion_at_[hidden]
> Subject: [std-discussion] It seems to a wording defect about template
> argument deduction for function parameter pack
> Message-ID:
> <CAANczrd3Q=
> 2WpWcinWDUck41vXPn0vH6ThK0wJgH5q__MKv9_g_at_[hidden]>
> Content-Type: text/plain; charset="utf-8"
>
> Consider the below code:
>
> template<typename...T>
> void func(T...args){
> }
> int main(){
> func(1,2.0,'c');
> }
>
> there's a rule that applied to it to deduce these template arguments for
> this function template (call). It is:
> >For a function parameter pack that occurs at the end of the
> parameter-declaration-list, deduction is performed for each remaining
> argument of the call, taking the type P of the declarator-id of the
> function parameter pack as the corresponding function template parameter
> type. Each deduction deduces template arguments for subsequent positions in
> the template parameter packs expanded by the function parameter pack.
>
> That means for the parameter-declaration T...args, it declares a function
> template park, hence the function parameter type that is used to against
> the type of function argument is T because ...args is the declarator-id of
> this declaration. So, for this function call func(1,2.0,'c'), template
> parameter pack T would be the set consists of {int,double,char}.
>
> However, consider the following variant:
>
> template<typename...T>
> void func(T...){
> }
> int main(){
> func(1,2.0,'c');
> }
>
> There's no declarator-id here, just an abstract-declarator that denote the
> ..., How would the quote be applied to this case? What's the corresponding
> function parameter type here? It seems to be a wording defect for this
> case.
> -------------- next part --------------
> HTML attachment scrubbed and removed
>
> ------------------------------
>
> Message: 3
> Date: Thu, 16 Jul 2020 22:36:34 +0800
> From: jim x <xmh970252187_at_[hidden]>
> To: std-discussion_at_[hidden]
> Subject: [std-discussion] The standard does not specify when to supply
> default arguments as template arguments
> Message-ID:
> <CAANczreSLdJ_E4ZQmQweNAwZP3wsdCBsy=
> xiFxGaPpE3x9dokQ_at_[hidden]>
> Content-Type: text/plain; charset="utf-8"
>
> 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 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 occuring
> 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.
> -------------- next part --------------
> HTML attachment scrubbed and removed
>
> ------------------------------
>
> Message: 4
> Date: Thu, 16 Jul 2020 17:19:00 +0200
> From: "Peter Sommerlad (C++)" <peter.cpp_at_[hidden]>
> To: jim x via Std-Discussion <std-discussion_at_[hidden]>
> Subject: Re: [std-discussion] It seems to a wording defect about
> template argument deduction for function parameter pack
> Message-ID: <5db0c956-414c-04d3-479f-cb5d1473c3ff_at_[hidden]>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Jim
>
> jim x via Std-Discussion wrote on 16.07.20 16:28:
> > Consider the below code:
> >
> > template<typename...T>
> > void func(T...args){
> > }
> > int main(){
> > ? func(1,2.0,'c');
> > }
> >
> > ?there's a rule that applied to it to deduce these template arguments
> > for this function template (call). It is:
> > >For a function parameter pack that occurs at the end of the
> > parameter-declaration-list, deduction is performed for each remaining
> > argument of the call, taking the type P of the declarator-id of the
> > function parameter pack as the corresponding function template parameter
> > type. Each deduction deduces template arguments for subsequent positions
> > in the template parameter packs expanded by the function parameter pack.
> >
> > That means for the parameter-declaration T...args, it declares a
> > function template park, hence the function parameter type that is used
> > to against the type of function argument is T because ...args is the
> > declarator-id of this declaration. So, for this function call
> > func(1,2.0,'c'), template parameter pack T would be the set consists of
> > {int,double,char}.
> >
> > However, consider the following variant:
> >
> > template<typename...T>
> > void func(T...){
> > }
> > int main(){
> > ? func(1,2.0,'c');
> > }
> >
> > There's no declarator-id here, just an abstract-declarator that denote
> > the ..., How would the quote be applied to this case? What's the
> > corresponding function parameter type here?? It seems to be a wording
> > defect for this case.
> >
> >
>
> What you are asking here corresponds to the situation where in a
> function definition you omit names for parameters that are unused int
> the function. So there is exactly the same thing happening as in your
> first example.
>
> Peter.
>
>
>
> --
> Peter Sommerlad
>
> Better Software: Consulting, Training, Reviews
> Modern, Safe & Agile C++
>
> peter.cpp_at_[hidden]
> +41 79 432 23 32
>
>
> ------------------------------
>
> Message: 5
> Date: Thu, 16 Jul 2020 17:33:52 +0200
> From: "Peter Sommerlad (C++)" <peter.cpp_at_[hidden]>
> To: jim x via Std-Discussion <std-discussion_at_[hidden]>
> Subject: Re: [std-discussion] The standard does not specify when to
> supply default arguments as template arguments
> Message-ID: <469da6d1-025a-28d4-2422-1df1f5b8f3e8_at_[hidden]>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> Jim,
>
> since func is also a template, the instantiation happens when func is
> instantiated, e.g., when it is called. A dependent template is
> instantiated when the surrounding template gets instantiated. That is
> the reason for the sometimes confusing C++ error messages when a nested
> inner template instantiation fails, due to a missing requirement of the
> arguments passed down, or a programming error.
>
> Regards
> Peter.
>
> jim x via Std-Discussion wrote on 16.07.20 16:36:
> > 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? 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
> > occuring 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.
> >
> >
>
>
> --
> Peter Sommerlad
>
> Better Software: Consulting, Training, Reviews
> Modern, Safe & Agile C++
>
> peter.cpp_at_[hidden]
> +41 79 432 23 32
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
>
> ------------------------------
>
> End of Std-Discussion Digest, Vol 16, Issue 23
> **********************************************
>

Received on 2020-07-16 12:03:22