Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is the definition of `top-level cv-qualifiers` in the C++11 Standard?

In the draft C++11 standard: N3337 I found several references to top-level cv-qualifiers, but no definition.

like image 562
Mao Avatar asked Jul 10 '14 12:07

Mao


People also ask

What are cv qualifiers?

CV stands for Constant-Volatile. The declaration of an object that is not preceded by const and/or volatile is a cv-unqualified type. On the other hand, the declaration of an object that is preceded by const and/or volatile is a cv-qualified type.

Is const qualified at the top level?

Whenever const appears immediately before or after the type of the identifier, that is considered a top-level qualifier.

What are qualifiers in C++?

In the C, C++, and D programming languages, a type qualifier is a keyword that is applied to a type, resulting in a qualified type. For example, const int is a qualified type representing a constant integer, while int is the corresponding unqualified type, simply an integer.


1 Answers

From Dan Saks's Top-Level cv-Qualifiers in Function Parameters:

In C++, a cv-qualifier that applies to the first level of a type is called a toplevel cv-qualifier. For example, in:

T *const p;

the top-level cv-qualifier is const, and in:

T const *volatile q;

the top-level cv-qualifier is volatile. On the other hand:

T const volatile *q;

has no top-level cv-qualifiers. In this case, the cv-qualifiers const and volatile appear at the second level.

The signature of a function includes all cv-qualifiers appearing in that function’s parameter types, except for those qualifiers appearing at the top-level of a parameter type.

For example, in:

int f(char const *p);

the const qualifier is not at the top level in the parameter declaration, so it is part of the function’s signature.

On the other hand, in:

int f(char *const p);

the const qualifier is at the top level, so it is not part of the function’s signature. This function has the same signature as:

int f(char *p);

I couldn't find a definition in the standard either but what I posted above is explicitly stated in N3337 §8.3.5-5

After producing the list of parameter types, any top-level cv-qualifiers modifying a parameter type are deleted when forming the function type.


Edit: At the time of writing the above post a definition in the standard could not be found but now there's one as pointed out by Shafik:

n4296 excerpt:

In this International Standard, the notation cv (or cv1 , cv2 , etc.), used in the description of types, represents an arbitrary set of cv-qualifiers, i.e., one of {const}, {volatile}, {const, volatile}, or the empty set. For a type cv T, the top-level cv-qualifiers of that type are those denoted by cv. [Example: The type corresponding to the type-id const int& has no top-level cv-qualifiers. The type corresponding to the typeid volatile int * const has the top-level cv-qualifier const. For a class type C, the type corresponding to the type-id void (C::* volatile)(int) const has the top-level cv-qualifier volatile. — end example ]

like image 118
Marco A. Avatar answered Sep 20 '22 04:09

Marco A.