static_casting a constexpr void* 的结果是常量表达式吗?
Is the result of static_casting a constexpr void* a constant expression?
clang 正在拒绝 gcc 允许的代码:
int main() {
static constexpr const void *vp = nullptr;
static constexpr const char *cp = static_cast<const char*>(vp);
}
具有以下内容:
error: constexpr variable 'cp' must be initialized by a constant expression
static constexpr const char *cp = static_cast<const char*>(vp);
阅读 N3797 5.9/2 中的最终清单后,我没有看到任何禁止 static_cast
在常量表达式中使用的内容。我是在看错地方还是误读了什么?或者我应该针对 clang 打开一个错误?
好吧,C++14 标准(以及您的(非最终)草案!)要求
A conditional-expression e
is a core constant expression unless
the evaluation of e
, following the rules of the abstract machine
(1.9), would evaluate one of the following expressions:
— a conversion from type cv void *
to a pointer-to-object type;
clang 正在拒绝 gcc 允许的代码:
int main() {
static constexpr const void *vp = nullptr;
static constexpr const char *cp = static_cast<const char*>(vp);
}
具有以下内容:
error: constexpr variable 'cp' must be initialized by a constant expression
static constexpr const char *cp = static_cast<const char*>(vp);
阅读 N3797 5.9/2 中的最终清单后,我没有看到任何禁止 static_cast
在常量表达式中使用的内容。我是在看错地方还是误读了什么?或者我应该针对 clang 打开一个错误?
好吧,C++14 标准(以及您的(非最终)草案!)要求
A conditional-expression
e
is a core constant expression unless the evaluation ofe
, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:— a conversion from type cv
void *
to a pointer-to-object type;