Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 269
Hector Avatar asked Oct 21 '15 15:10

Hector


People also ask

What is ambiguity in C?

When you derive classes, ambiguities can result if base and derived classes have members with the same names. Access to a base class member is ambiguous if you use a name or qualified name that does not refer to a unique function or object.

Is C an ambiguous language?

Programming languages like Pascal, C and Java follow this convention, so there is no ambiguity in the semantics of the language, though the use of a parser generator may lead to ambiguous grammars.

What is ambiguity error?

Ambiguity errors occur when erasure causes two seemingly distinct generic declarations to resolve to the same erased type, causing a conflict.

What is ambiguity error and how do you resolve it?

[‚am·bə′gyü·əd·ē ‚er·ər] (computer science) An error in reading a number represented in a digital display that can occur when this representation is changing; for example, the number 699 changing to 700 might be read as 799 because of imprecise synchronization in the changing of digits.


1 Answers

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.[...]

like image 133
Shafik Yaghmour Avatar answered Sep 22 '22 00:09

Shafik Yaghmour