c++ - C++11标准中 `top-level cv-qualifiers`的定义在哪里?

标签 c++ c++11 language-lawyer

the draft C++11 standard: N3337我找到了多个对 top-level cv-qualifiers 的引用,但没有定义。

最佳答案

来自 Dan Saks 的 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);

我在标准中也找不到定义,但我在上面发布的内容在 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.


编辑: 在撰写上述帖子时,无法找到标准中的定义,但现在有一个 as pointed out by Shafik :

n4296 摘录:

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 ]

关于c++ - C++11标准中 `top-level cv-qualifiers`的定义在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24676824/

相关文章:

c++ - 在 std::vector 中实例化对象时出现错误 C2280/复制构造函数问题?

c++ - 在 C++ STL 中使用 auto 关键字

c++ - 终止处理程序可以抛出异常吗?

c++ - 是否所有 C++ 编译器都支持 async/await 关键字?

c++ - C++ 中的 3-d 动画

c++ - 覆盖私有(private)函数

c++ - move 或命名返回值优化 (NRVO)?

c - 在无法到达的路径上具有未定义行为的程序的行为是否已定义?

c++ - 交换包含放置新创建对象的存储缓冲区

CLR dll 需要 C++ .lib 文件,但非 CLR 不需要