C++ 标准 N3337 5.2.10 第 7 条中的“类型纯右值”是什么意思?

What does this mean "prvalue of type“ in C++ standard N3337 5.2.10 clause 7?

C++ draft standard N3337 section 5.2.10 Reinterpret cast clause 7强调我的):

An object pointer can be explicitly converted to an object pointer to a different type. When a prvalue v of type “pointer to T1” is converted to the type “pointer to cv T2”, the result is static_cast<cv T2*>(static_cast<cv void*>(v)) if both T1 and T2 are standard-layout types (3.9) and the alignment requirements of T2 are no stricter than those of T1, or if either type is void.

这是否意味着表达式 v 是纯右值?。如果是,那么

int a = 0x1234;
int *pa = &a;
char *pc = reinterpret_cast<char *>(pa);

上面,变量pa是一个lvalue,那么我们是否可以认为如果lvalue的变量在正确的表达式中,变量就是一个prvalue类型?.

cppreference 是你的朋友,如果我们进入主题 Value categories 它告诉我们 prvalue 是:

a prvalue (“pure” rvalue) is an expression whose evaluation either

  • computes the value of the operand of an operator (such prvalue has no result object), or
  • initializes an object or a bit-field (such prvalue is said to have a result object). All class and array prvalues have a result object even if it is discarded. In certain contexts, temporary materialization occurs to create a temporary as the result object;

这不是自动启发,但它们提供了一组非常好的 examples below 我将引用一些指针示例:

The following expressions are prvalue expressions:

...

  • &a, the built-in address-of expression;
    ...
  • the this pointer;
    ....

因此,将 this 指针或 address-of 的结果转换为该类型指针的 const 将符合措辞(假设它还不是 const),例如:

{
  int x = 0;
  const int *p = reinterpret_cast<const int*>(&x);
}

规范使用v来表示一个表达式。它不一定是变量的名称。

在您的示例中,您引用的段落不直接适用,因为 pa 是左值。相反,首先应用 lvalue-to-rvalue conversion,然后应用本段。