Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
(char*)(nullptr)对constexpr求值的指针算术错误 下面的程序是否正式正确C++(?) #包括 #定义案例1 #如果CASE==1 constexpr void*crash=static_cast(static_cast(nullptr)+1); #elif案例==2 constexpr void*crash=nullptr; #elif案例==3 const void*crash=static_cast(static_cast(nullptr)+1); #恩迪夫 int main(){ std::cout_C++_Nullptr - Fatal编程技术网

(char*)(nullptr)对constexpr求值的指针算术错误 下面的程序是否正式正确C++(?) #包括 #定义案例1 #如果CASE==1 constexpr void*crash=static_cast(static_cast(nullptr)+1); #elif案例==2 constexpr void*crash=nullptr; #elif案例==3 const void*crash=static_cast(static_cast(nullptr)+1); #恩迪夫 int main(){ std::cout

(char*)(nullptr)对constexpr求值的指针算术错误 下面的程序是否正式正确C++(?) #包括 #定义案例1 #如果CASE==1 constexpr void*crash=static_cast(static_cast(nullptr)+1); #elif案例==2 constexpr void*crash=nullptr; #elif案例==3 const void*crash=static_cast(static_cast(nullptr)+1); #恩迪夫 int main(){ std::cout,c++,nullptr,C++,Nullptr,不能仅对constexpr中的任何指针执行算术运算。 您可以对指向数组的指针(或作为一个大小数组的对象)执行算术运算,只要您不在数组之外。…或超出数组末尾一个以上的元素。以下两条语句是否导致您的答案?如果是这种情况,您能将它们添加到您的答案中吗?(语句1)第8.5.6节第4段of的[expr.add]表示,静态强制转换(静态强制转换(nullptr)+1)给出了未定义的行为。(声明2)第8.6节[expr.const]项(2.6)第2段的说明是,如果指针算术导致未定义的行为,这不是核心常量表达式

不能仅对constexpr中的任何指针执行算术运算。

您可以对指向数组的指针(或作为一个大小数组的对象)执行算术运算,只要您不在数组之外。

…或超出数组末尾一个以上的元素。以下两条语句是否导致您的答案?如果是这种情况,您能将它们添加到您的答案中吗?(语句1)第8.5.6节第4段of的[expr.add]表示,
静态强制转换(静态强制转换(nullptr)+1)
给出了未定义的行为。(声明2)第8.6节[expr.const]项(2.6)第2段的说明是,如果指针算术导致未定义的行为,这不是核心常量表达式。因此
constepr
不适用于此表达式,并导致错误。
error: reinterpret_cast from integer to pointer
   constexpr void* crash = static_cast<void*>(static_cast<char*>(nullptr)+1);
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
null.cc(3): error C2131: expression did not evaluate to a constant
null.cc(3): note: failure was caused by unevaluable pointer value