【发布时间】:2013-12-14 14:36:29
【问题描述】:
我有以下 C++11 代码。
#include <type_traits>
using IntType = unsigned long long;
template <IntType N> struct Int {};
template <class T>
struct is_int : std::false_type {};
template <long long N>
struct is_int<Int<N>> : std::true_type {};
int main()
{
static_assert (is_int<Int<0>>::value, "");
return 0;
}
Clang++ 3.3 编译代码但在 g++ 4.8.2 上静态断言失败
$ g++ -std=c++11 main.cpp
main.cpp: In function ‘int main()’:
main.cpp:15:5: error: static assertion failed:
static_assert (is_int<Int<0>>::value, "");
^
$
问题是由不同的积分模板参数引起的。 在这种情况下哪个编译器是正确的?
【问题讨论】:
-
好问题,非常微妙。
-
只是一个注释 - 在 VS2010 上编译(将
using更改为typedef。 -
@jrok 不是,这个问题是关于 Clang 中的一个错误
-
@AlecTeal 哦,所以你知道这是 clang 的错误吗?我急切地等待着你的答复。 :)
标签: c++ templates c++11 g++ clang++