Date: Wed, 3 Apr 2024 08:55:17 -0400
> What would an example be of a nodeclspec-function-declaration used in a
template-declaration ?
template <typename T> C<T>::C();
The point of nodeclspec-function-declaration is to allow non-definition
function declarations that don't have a syntactic return type in these
template-related contexts. (Conversion functions do have a semantic return
type, but as far as the syntax is concerned, there's no return type in
front of a function declarator like "operator int() const;" since "operator
int" is the function name.) This sort of declaration can't occur in
namespace scope because constructors, destructors, and conversion functions
are always class members, and redeclaring a non-template member function
must be the definition: "C::C() = default;" is valid but just "C::C();" is
not. The nodeclspec-function-declaration symbol happens not to be involved
for function declarations inside a class scope. In that case, the syntactic
return type is optional in the grammar, with an explicit semantic rule that
it can only be omitted for constructors, destructors, and conversion
functions (C++20 [class.mem]/12).
-- Andrew Schepler
On Sun, Mar 31, 2024 at 10:25 PM Russell Shaw via Std-Discussion <
std-discussion_at_[hidden]> 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]
> ------------------
>
> nodeclspec-function-declaration :
> attribute-specifier-seqopt declarator ;
>
>
> I don't understand Note 3.
>
> What would an example be of a nodeclspec-function-declaration used in a
> template-declaration ?
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
template-declaration ?
template <typename T> C<T>::C();
The point of nodeclspec-function-declaration is to allow non-definition
function declarations that don't have a syntactic return type in these
template-related contexts. (Conversion functions do have a semantic return
type, but as far as the syntax is concerned, there's no return type in
front of a function declarator like "operator int() const;" since "operator
int" is the function name.) This sort of declaration can't occur in
namespace scope because constructors, destructors, and conversion functions
are always class members, and redeclaring a non-template member function
must be the definition: "C::C() = default;" is valid but just "C::C();" is
not. The nodeclspec-function-declaration symbol happens not to be involved
for function declarations inside a class scope. In that case, the syntactic
return type is optional in the grammar, with an explicit semantic rule that
it can only be omitted for constructors, destructors, and conversion
functions (C++20 [class.mem]/12).
-- Andrew Schepler
On Sun, Mar 31, 2024 at 10:25 PM Russell Shaw via Std-Discussion <
std-discussion_at_[hidden]> 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]
> ------------------
>
> nodeclspec-function-declaration :
> attribute-specifier-seqopt declarator ;
>
>
> I don't understand Note 3.
>
> What would an example be of a nodeclspec-function-declaration used in a
> template-declaration ?
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
>
Received on 2024-04-03 12:55:30