C++ Logo

std-discussion

Advanced search

Re: nodeclspec-function-declaration

From: Russell Shaw <rjshaw_at_[hidden]>
Date: Fri, 26 Apr 2024 16:06:43 +1000
On 26/4/24 03:06, Jens Maurer via Std-Discussion wrote:
>
>
> On 25/04/2024 15.33, Russell Shaw via Std-Discussion wrote:
>> Hi,
>>
>> In 9.12 p164 General [dcl.dcl] 14882:2020(E) :
>>
>> ------------------
>> 12
>> A nodeclspec-function-declaration shall declare a constructor, destructor, or
>> conversion function.
>>
>> [Note 3 : A nodeclspec-function-declaration can only be used in a
>> template-declaration (13.1), explicit-instantiation (13.9.3),
>> or explicit-specialization (13.9.4). — end note]
>>
>> ------------------
>>
>> I can get the 'explicit-instantiation' and 'explicit-specialization' to work,
>> but how do i get the 'template-declaration' to work ?
>>
>> ++++++++++++++++++
>>
>> template<typename T> struct S {
>> S();
>> };
>>
>> template<> S<int>::S();
>>
>> template S<int>::S();
>>
>> template<typename T> S<T>::S(); <-- error: declaration of ‘S<T>::S()’
>> outside of class is not definition [-fpermissive]
>
> How about
>
> struct S {
> template<class T> S(T);
> };

Hello Jens,

Even though the BNF allows a 'nodeclspec-function-declaration' outside a struct,
it seems the semantics are that for a constructor, it is only allowed inside a
struct. I'll accept that as the answer.

Received on 2024-04-26 06:06:49