enable_if 使用 clang++ 和 g++ 的不同行为
Different behavior with enable_if using clang++ and g++
当我编译以下代码时:
#include <boost/numeric/interval.hpp>
#include <complex>
int main(){
std::complex<boost::numeric::interval<double> > my_interval(1,1);
my_interval *= my_interval;
return 0;}
使用
g++ -std=c++14 main.cpp
或
clang++ -std=c++14 main.cpp
我有两种不同的行为。 g++ 编译正常,而 clang++ 编译失败,因为调用
std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
禁用某些必需的功能。有简单的解决方法吗?我做错了什么吗?
版本:
g++ (MacPorts gcc5 5.5.0_1) 5.5.0
Apple LLVM 版本 8.1.0 (clang-802.0.38)
完整且完整的错误:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:599:9: error:
no matching function for call to 'isnan'
if (isnan(__x) && isnan(__y))
^~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:312:27: note:
in instantiation of function template specialization
'std::__1::operator*<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > > >' requested
here
*this = *this * complex(__c.real(), __c.imag());
^
main.cpp:6:15: note: in instantiation of function template specialization
'std::__1::complex<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > >
>::operator*=<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > > >' requested
here
my_interval *= my_interval;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:424:25: note:
candidate template ignored: disabled by 'enable_if' [with _A1 =
boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > >]
typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
看起来 Boost.Numeric 区间代码依赖于不可移植的行为 - 准确地说,调用 isnan
非算术类型的能力。
<cmath>
中的例程只需要与算术类型一起工作,这些类型被(广泛地)定义为 "built in integral and floating point types"。
libstdc++ 在这里实现了扩展以支持其他类型,libc++ 没有。
Inside baseball:标准的相关部分(和其他部分)
- [cmath.syn]/2 - 提供了哪些重载的描述。
- [basic.fundamental]/8 - 什么是算术类型。
- 这作为 LWG issue 2086
的一部分进行了讨论
[后来]:一个更基本的问题(导致我上面说的)是std::__1::complex<boost::numeric::interval<double...>
.
的使用
这也是不可移植的:[complex.numbers]/2 说:
The effect of instantiating the template complex for any type other than float, double, or long double is unspecified.
当我编译以下代码时:
#include <boost/numeric/interval.hpp>
#include <complex>
int main(){
std::complex<boost::numeric::interval<double> > my_interval(1,1);
my_interval *= my_interval;
return 0;}
使用
g++ -std=c++14 main.cpp
或
clang++ -std=c++14 main.cpp
我有两种不同的行为。 g++ 编译正常,而 clang++ 编译失败,因为调用
std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
禁用某些必需的功能。有简单的解决方法吗?我做错了什么吗?
版本:
g++ (MacPorts gcc5 5.5.0_1) 5.5.0
Apple LLVM 版本 8.1.0 (clang-802.0.38)
完整且完整的错误:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:599:9: error:
no matching function for call to 'isnan'
if (isnan(__x) && isnan(__y))
^~~~~
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/complex:312:27: note:
in instantiation of function template specialization
'std::__1::operator*<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > > >' requested
here
*this = *this * complex(__c.real(), __c.imag());
^
main.cpp:6:15: note: in instantiation of function template specialization
'std::__1::complex<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > >
>::operator*=<boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > > >' requested
here
my_interval *= my_interval;
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cmath:424:25: note:
candidate template ignored: disabled by 'enable_if' [with _A1 =
boost::numeric::interval<double,
boost::numeric::interval_lib::policies<boost::numeric::interval_lib::rounded_math<double>,
boost::numeric::interval_lib::checking_strict<double> > >]
typename std::enable_if<std::is_arithmetic<_A1>::value, bool>::type
看起来 Boost.Numeric 区间代码依赖于不可移植的行为 - 准确地说,调用 isnan
非算术类型的能力。
<cmath>
中的例程只需要与算术类型一起工作,这些类型被(广泛地)定义为 "built in integral and floating point types"。
libstdc++ 在这里实现了扩展以支持其他类型,libc++ 没有。
Inside baseball:标准的相关部分(和其他部分)
- [cmath.syn]/2 - 提供了哪些重载的描述。
- [basic.fundamental]/8 - 什么是算术类型。
- 这作为 LWG issue 2086 的一部分进行了讨论
[后来]:一个更基本的问题(导致我上面说的)是std::__1::complex<boost::numeric::interval<double...>
.
这也是不可移植的:[complex.numbers]/2 说:
The effect of instantiating the template complex for any type other than float, double, or long double is unspecified.