Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/136.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
C++ 使用std::acos和clang++;不是g++;_C++_Compiler Errors_C++14_Constexpr_Clang++ - Fatal编程技术网

C++ 使用std::acos和clang++;不是g++;

C++ 使用std::acos和clang++;不是g++;,c++,compiler-errors,c++14,constexpr,clang++,C++,Compiler Errors,C++14,Constexpr,Clang++,我想尝试将一个项目从gcc迁移到clang++。我承认我的无知,我不知道为什么会出现下面的代码 template <typename T> constexpr T pi{std::acos(T(-1.0))}; 模板 constexpr tpi{std::acos(T(-1.0))}; 使用g++以静默方式编译,但clang++会产生错误 trig.hpp:3:13: error: constexpr variable 'pi<float>' must be init

我想尝试将一个项目从gcc迁移到clang++。我承认我的无知,我不知道为什么会出现下面的代码

template <typename T>
constexpr T pi{std::acos(T(-1.0))};
模板
constexpr tpi{std::acos(T(-1.0))};
使用g++以静默方式编译,但clang++会产生错误

trig.hpp:3:13: error: constexpr variable 'pi<float>' must be initialized by a constant expression
constexpr T pi{std::acos(T(-1.0))};
trig.hpp:3:13:错误:constexpr变量“pi”必须由常量表达式初始化
constexpr tpi{std::acos(T(-1.0))};
我希望有比我更了解这件事的人能启发我


注意:尝试使用-std=C++14和C++1y。在clang版本3.6.2下失败(标签/发行版\u 362/最终版)。适用于g++(GCC)5.2.0。

这里的Clang是正确的,我们不允许在常量表达式中使用
acos

问题在于标准中没有标记constexpr,而是。这是一个问题,最终应在gcc中解决

通常用于固定折叠,我们可以看到,如果我们将
-fno builtin
与gcc一起使用,它将禁用此不一致行为,我们将收到以下错误:

error: call to non-constexpr function 'double acos(double)'
constexpr T pi{std::acos(T(-1.0))};
                         ^

这里的叮当声是正确的,我们不允许在常量表达式中使用
acos

问题在于标准中没有标记constexpr,而是。这是一个问题,最终应在gcc中解决

通常用于固定折叠,我们可以看到,如果我们将
-fno builtin
与gcc一起使用,它将禁用此不一致行为,我们将收到以下错误:

error: call to non-constexpr function 'double acos(double)'
constexpr T pi{std::acos(T(-1.0))};
                         ^

与@ShafikYaghmour有关的外观我认为我搜索得很好。我错了。非常感谢。这确实是一个令人失望的结果。我还感到惊讶的是,GCC在允许标准中禁止的内容时,至少没有发出警告。我也在用书呆子编译!如果你想写一个答案,我会接受的。我并不惊讶这个问题没有出现,关键字的重叠似乎很小。大约一年前,当我第一次遇到这个问题时,我什么也找不到,直到我无意中遇到语言工作组2013年版,我才设法把这些片段拼凑起来。与@ShafikYaghmour相关的外观我认为我搜索得很好。我错了。非常感谢。这确实是一个令人失望的结果。我还感到惊讶的是,GCC在允许标准中禁止的内容时,至少没有发出警告。我也在用书呆子编译!如果你想写一个答案,我会接受的。我并不惊讶这个问题没有出现,关键字的重叠似乎很小。大约一年前,当我第一次遇到这个问题时,我找不到任何东西,直到我意外地遇到语言工作组2013年版,我才设法把这些片段拼凑起来。