Wake up Brazil
Wake up Brazil

Reputation: 3411

What is the relevance of this statement in 7.1.6.1/1 in the C++ Standard?

7.1.6.1/1 contains the following statement (emphasis mine):

There are two cv-qualifiers, const and volatile. If a cv-qualifier appears in a decl-specifier-seq, the init-declarator-list of the declaration shall not be empty.

What is the relevance of the statement in bold above? In other words, is it possible to produce an example of a cv-unqualified type in a decl-specifier-seq, in which the init-declarator-list of the declaration is empty?

Upvotes: 7

Views: 273

Answers (1)

user743382
user743382

Reputation:

Sure, most class and enum definitions make use of it:

struct A { }; // valid
const struct B { }; // invalid, const would have no meaning
const struct C { } c { }; // valid

There is nothing else. An init-declarator-list is only used in a simple-declaration, and for that, the standard (C++11) states:

7 Declarations [dcl.dcl]

3 In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class (Clause 9) or enumeration (7.2), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated-type-specifier with a class-key (9.1), or an enum-specifier.

Upvotes: 11

Related Questions