【发布时间】:2016-10-08 21:19:11
【问题描述】:
在一个非常简单的情况下,使用受约束的构造函数,测试参数的可转换性,在 clang 中会产生错误,但在 g++ 中不会:
#include <type_traits>
template <class T, class U>
constexpr bool Convertible = std::is_convertible<T,U>::value && std::is_convertible<U,T>::value;
template <class T>
struct A
{
template <class S, class = std::enable_if_t<Convertible<S,T>> >
A(S const&) {}
};
int main()
{
A<double> s = 1.0;
}
也许这个问题与Is clang's c++11 support reliable?有关
clang 给出的错误是:
error: no member named 'value' in 'std::is_convertible<double, A<double> >'
constexpr bool Convertible = std::is_convertible<T,U>::value && std::is_convertible<U,T>::value;
~~~~~~~~~~~~~~~~~~~~~~~~~~^
我试过了
- g++-5.4、g++-6.2(无错误)
- clang++-3.5、clang++-3.8、clang++-3.9(错误)
带参数-std=c++1y 和-stdlib=libstdc++ 或-stdlib=libc++。
哪个编译器是正确的?它是clang还是gcc中的错误?还是由于某些原因导致行为未定义,因此两个编译器都正确?
【问题讨论】:
标签: gcc clang c++14 sfinae typetraits