【发布时间】:2017-01-11 02:38:07
【问题描述】:
更新到 Visual Studio 2015 Update 3(来自 Visual Studio 2015)后,此代码不再编译:
#include<cmath>
#include<complex>
int main()
{
std::complex<double> update(0.0, 0.0);
double x = std::abs(update);
return 1;
}
运行编译器时出现以下错误:
c:\projects\foo\win64>cl /EHsc /fp:strict foo.cc
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24213.1 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
foo.cc
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(232): er
ror C2131: expression did not evaluate to a constant
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(232): no
te: failure was caused by an undefined arithmetic operation
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\INCLUDE\xcomplex(253): no
te: see reference to function template instantiation '_Ty std::_Fabs<double>(con
st std::complex<double> &,int *)' being compiled
with
[
_Ty=double
]
foo.cc(6): note: see reference to function template instantiation '_Ty std::abs<
double>(const std::complex<double> &)' being compiled
with
[
_Ty=double
]
这个问题似乎与我对 fp:strict 的使用有关,这是正确的 IEEE 浮点所必需的。这是我的代码的问题吗?
【问题讨论】:
-
“正确的 IEEE 浮点所必需的”有点夸大其词。
-
@Alan Stokes 不是真的(恕我直言)。如果您依赖 IEEE-754 的指定行为,那么您需要
/fp:strict使用Microsoft 的编译器(嗯,这是默认设置,但您仍然需要它实现的功能 -其他选项不执行 754)... -
已确认,看起来像一个编译器错误 - 无法通过除法获得 constexpr
-
@IgorTandetnik,感谢您找到这个。这是一个真正的拖累,因为 appveyor 已经转移到这个编译器。
标签: c++ visual-studio debugging visual-c++