【发布时间】:2017-11-16 06:14:24
【问题描述】:
不出所料,下面的代码does not compile。
#include <type_traits>
#include <utility>
int main()
{
using T = std::pair<const int, int>;
const auto ok = std::is_assignable<T, T>::value; // true
T x;
T y;
x = y; // compiler error
}
但是okis true的值用下面三个编译器。
- g++ (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
- clang 版本 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
- MSVC++ 2017 15.2 26430.6
这是为什么?
【问题讨论】:
-
你能尝试用一个系统来编译它,给你实际的错误信息,然后给我们看吗?
-
你是如何准确推断出它是真的? OK 上的静态断言失败。 coliru.stacked-crooked.com/a/aba0debbfc609c11
-
std::cout << std::boolalpha << ok << '\n';使用 Clang 5.0 输出false。 -
ok适用于 gcc -
godbolt.org/g/cMfcBP 正如霍尔特所说,gcc