62 lines
3.3 KiB
Markdown
62 lines
3.3 KiB
Markdown
[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.3 Function 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.3 Function 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.1 General [dcl.spec.general]")[.](#1.sentence-2)
|
||
|
||
[function-specifier:](#nt:function-specifier "9.2.3 Function specifiers [dcl.fct.spec]")
|
||
virtual
|
||
[*explicit-specifier*](#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]")
|
||
|
||
[explicit-specifier:](#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]")
|
||
explicit ( [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant 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.3 Virtual 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.3 Function 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.2 Conversion by constructor") and [[class.conv.fct]](class.conv.fct "11.4.8.3 Conversion 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.3 Function specifiers [dcl.fct.spec]"),
|
||
the [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]"), if supplied, shall be a
|
||
contextually converted constant expression of type bool ([[expr.const]](expr.const "7.7 Constant expressions"))[.](#4.sentence-1)
|
||
|
||
The [*explicit-specifier*](#nt:explicit-specifier "9.2.3 Function specifiers [dcl.fct.spec]") explicit without a [*constant-expression*](expr.const#nt:constant-expression "7.7 Constant expressions [expr.const]") is equivalent to
|
||
the [*explicit-specifier*](#nt:explicit-specifier "9.2.3 Function 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.3 Function 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*]
|