Hector
Hector

Reputation: 2534

C++ standard ambiguity

As far as I can see in the standard, the following code is valid. It compiles in MSVC1025.

const struct omg;
struct omg volatile;

int main()
{
    return 0;
}

The qualifiers const and volatile seem purposeless in those declarations. They do not help nor hurt neither the compiler nor the programmer.

The standard does not seem bent on weeding out these "empty ambiguities". In the case of the empty declaration ;, it is explicitly allowed.

Are there other cases of tokens that, after preprocessing, are irrelevant for the meaning of the expression?

Upvotes: 7

Views: 281

Answers (1)

Shafik Yaghmour
Shafik Yaghmour

Reputation: 158629

Both clang and gcc reject this code using -pedantic-errors. clang provides the following error:

error: 'const' is not permitted on a declaration of a type [-Werror,-Wmissing-declarations]
const struct omg;
^

error: 'volatile' is not permitted on a declaration of a type [-Werror,-Wmissing-declarations]

the draft C++ standard section 7.1.6.1 The cv-qualifiers [dcl.type.cv] says:

[...]If a cv-qualifier appears in a decl-specifier-seq, the init-declarator-list of the declaration shall not be empty.[...]

Upvotes: 4

Related Questions