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

62 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[dcl.fct.spec]
# 9 Declarations [[dcl]](./#dcl)
## 9.2 Specifiers [[dcl.spec]](dcl.spec#dcl.fct.spec)
### 9.2.3 Function specifiers [dcl.fct.spec]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L689)
A[*function-specifier*](#nt:function-specifier "9.2.3Function specifiers[dcl.fct.spec]") can be used only in a function declaration[.](#1.sentence-1)
At most one [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]") and
at most one virtual keyword shall appear in
a [*decl-specifier-seq*](dcl.spec.general#nt:decl-specifier-seq "9.2.1General[dcl.spec.general]")[.](#1.sentence-2)
[function-specifier:](#nt:function-specifier "9.2.3Function specifiers[dcl.fct.spec]")
virtual
[*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]")
[explicit-specifier:](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]")
explicit ( [*constant-expression*](expr.const#nt:constant-expression "7.7Constant expressions[expr.const]") )
explicit
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L709)
The virtual specifier shall be used only in the initial
declaration of a non-static member function; see [[class.virtual]](class.virtual "11.7.3Virtual functions")[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L714)
An [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]") shall be used only in the declaration of
a constructor or conversion function within its class definition;
see [[class.conv.ctor]](class.conv.ctor "11.4.8.2Conversion by constructor") and [[class.conv.fct]](class.conv.fct "11.4.8.3Conversion functions")[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L720)
In an [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]"),
the [*constant-expression*](expr.const#nt:constant-expression "7.7Constant expressions[expr.const]"), if supplied, shall be a
contextually converted constant expression of type bool ([[expr.const]](expr.const "7.7Constant expressions"))[.](#4.sentence-1)
The [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]") explicit without a [*constant-expression*](expr.const#nt:constant-expression "7.7Constant expressions[expr.const]") is equivalent to
the [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]") explicit(true)[.](#4.sentence-2)
If the constant expression evaluates to true,
the function is explicit[.](#4.sentence-3)
Otherwise, the function is not explicit[.](#4.sentence-4)
A ( token that follows explicit is parsed as
part of the [*explicit-specifier*](#nt:explicit-specifier "9.2.3Function specifiers[dcl.fct.spec]")[.](#4.sentence-5)
[*Example [1](#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*]