c++ - MSVC 2015 无法编译 constexpratan

标签 c++ visual-studio c++11

我在我的项目中使用了Mingw-w64 编译器。现在我正在使用 MSVC2015 编译项目。以下行给出错误:

constexpr double pi = 4*std::atan(1);

错误:

error: C2131: expression did not evaluate to a constant

但是在mingw中编译没有任何问题。

最佳答案

MSVC 在这种情况下是正确的,来自 [constexpr.functions]p1

This document explicitly requires that certain standard library functions are constexpr. An implementation shall not declare any standard library function signature as constexpr except for those where it is explicitly required.

正如您从我突出显示的最后一句话中看到的那样,如果标准没有这样说,则不允许实现声明函数 constexpr

现在标准说 atanconstexpr 吗?没有,从[c.math]中的签名可以看出:

float atan(float x);  // see [library.c]
double atan(double x);

关于c++ - MSVC 2015 无法编译 constexpratan,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37952267/

相关文章:

C++ 类变量作为方法参数?

c# - 我该如何解决 "The query results cannot be enumerated more than once"?

c++ - 我如何判断哪个版本的 g++ 是使用 `atomic` 而不是 `cstdatomic` 的最早版本?

c++ - 在main中调用类的函数

c++ - 为什么成员模板方法必须在类外使用 template<> 进行专门化

c++ - 仅从 QTextEdit 小部件获取可见文本

c++ - C++中bool数据类型的比较

c++ - 将字符串中的数据提取到映射中的有效方法是什么?

c# - Visual Studio Intellisense 评论来自哪里?

c# - Visual Form 继承不适用于 Visual Studio 2008 中的智能设备/紧凑型框架