Files
2025-10-25 03:02:53 +03:00

3.3 KiB

[dcl.fct.spec]

9 Declarations [dcl]

9.2 Specifiers [dcl.spec]

9.2.3 Function specifiers [dcl.fct.spec]

1

#

Afunction-specifier can be used only in a function declaration.

At most one explicit-specifier and at most one virtual keyword shall appear in a decl-specifier-seq.

function-specifier:
virtual
explicit-specifier

explicit-specifier:
explicit ( constant-expression )
explicit

2

#

The virtual specifier shall be used only in the initial declaration of a non-static member function; see [class.virtual].

3

#

An explicit-specifier shall be used only in the declaration of a constructor or conversion function within its class definition; see [class.conv.ctor] and [class.conv.fct].

4

#

In an explicit-specifier, the constant-expression, if supplied, shall be a contextually converted constant expression of type bool ([expr.const]).

The explicit-specifier explicit without a constant-expression is equivalent to the explicit-specifier explicit(true).

If the constant expression evaluates to true, the function is explicit.

Otherwise, the function is not explicit.

A ( token that follows explicit is parsed as part of the explicit-specifier.

[Example 1: struct S {explicit(sizeof(char[2])) S(char); // error: narrowing conversion of value 2 to type boolexplicit(sizeof(char)) S(bool); // OK, conversion of value 1 to type bool is non-narrowing}; — end example]