83 lines
4.7 KiB
Markdown
83 lines
4.7 KiB
Markdown
[dcl.spec.general]
|
||
|
||
# 9 Declarations [[dcl]](./#dcl)
|
||
|
||
## 9.2 Specifiers [[dcl.spec]](dcl.spec#general)
|
||
|
||
### 9.2.1 General [dcl.spec.general]
|
||
|
||
[1](#1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L431)
|
||
|
||
The specifiers that can be used in a declaration are
|
||
|
||
[decl-specifier:](#nt:decl-specifier "9.2.1 General [dcl.spec.general]")
|
||
[*storage-class-specifier*](dcl.stc#nt:storage-class-specifier "9.2.2 Storage class specifiers [dcl.stc]")
|
||
[*defining-type-specifier*](dcl.type.general#nt:defining-type-specifier "9.2.9.1 General [dcl.type.general]")
|
||
[*function-specifier*](dcl.fct.spec#nt:function-specifier "9.2.3 Function specifiers [dcl.fct.spec]")
|
||
friend
|
||
typedef
|
||
constexpr
|
||
consteval
|
||
constinit
|
||
inline
|
||
|
||
[decl-specifier-seq:](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")
|
||
[*decl-specifier*](#nt:decl-specifier "9.2.1 General [dcl.spec.general]") [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]")opt
|
||
[*decl-specifier*](#nt:decl-specifier "9.2.1 General [dcl.spec.general]") [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")
|
||
|
||
The optional [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") in a [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]") appertains to the type determined by the preceding[*decl-specifier*](#nt:decl-specifier "9.2.1 General [dcl.spec.general]")*s* ([[dcl.meaning]](dcl.meaning "9.3.4 Meaning of declarators"))[.](#1.sentence-2)
|
||
|
||
The [*attribute-specifier-seq*](dcl.attr.grammar#nt:attribute-specifier-seq "9.13.1 Attribute syntax and semantics [dcl.attr.grammar]") affects the type only for the declaration it appears in, not other declarations involving the
|
||
same type[.](#1.sentence-3)
|
||
|
||
[2](#2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L459)
|
||
|
||
At most one of each of the [*decl-specifier*](#nt:decl-specifier "9.2.1 General [dcl.spec.general]")*s*friend, typedef, or inline shall appear in a [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")[.](#2.sentence-1)
|
||
|
||
At most one of
|
||
the constexpr, consteval, and constinit keywords
|
||
shall appear in a [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")[.](#2.sentence-2)
|
||
|
||
[3](#3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L467)
|
||
|
||
If a [*type-name*](dcl.type.simple#nt:type-name "9.2.9.3 Simple type specifiers [dcl.type.simple]") is encountered while parsing a [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]"),
|
||
it is interpreted as part of the [*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]") if and only if there is no
|
||
previous [*defining-type-specifier*](dcl.type.general#nt:defining-type-specifier "9.2.9.1 General [dcl.type.general]") other than a [*cv-qualifier*](dcl.decl.general#nt:cv-qualifier "9.3.1 General [dcl.decl.general]") in the[*decl-specifier-seq*](#nt:decl-specifier-seq "9.2.1 General [dcl.spec.general]")[.](#3.sentence-1)
|
||
|
||
The sequence shall be self-consistent as
|
||
described below[.](#3.sentence-2)
|
||
|
||
[*Example [1](#example-1)*: typedef char* Pc;static Pc; // error: name missing
|
||
|
||
Here, the declaration static Pc is ill-formed because no
|
||
name was specified for the static variable of type Pc[.](#3.sentence-3)
|
||
|
||
To get a
|
||
variable called Pc, a [*type-specifier*](dcl.type.general#nt:type-specifier "9.2.9.1 General [dcl.type.general]") (other thanconst or volatile) has to be present to indicate that
|
||
the [*typedef-name*](dcl.typedef#nt:typedef-name "9.2.4 The typedef specifier [dcl.typedef]") Pc is the name being (re)declared,
|
||
rather than being part of the [*decl-specifier*](#nt:decl-specifier "9.2.1 General [dcl.spec.general]") sequence[.](#3.sentence-4)
|
||
|
||
For
|
||
another example,void f(const Pc); // void f(char* const) (not const char*)void g(const int Pc); // void g(const int)
|
||
|
||
â *end example*]
|
||
|
||
[4](#4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/declarations.tex#L493)
|
||
|
||
[*Note [1](#note-1)*:
|
||
|
||
Since signed, unsigned, long, and short by default imply int, a [*type-name*](dcl.type.simple#nt:type-name "9.2.9.3 Simple type specifiers [dcl.type.simple]") appearing after one
|
||
of those specifiers is treated as the name being (re)declared[.](#4.sentence-1)
|
||
|
||
[*Example [2](#example-2)*: void h(unsigned Pc); // void h(unsigned int)void k(unsigned int Pc); // void k(unsigned int) â *end example*]
|
||
|
||
â *end note*]
|