我刚刚遇到以下代码,如果使用了templaterized static_assert
,那么第一个pred1
将不会失败,并且在main x
中声明了一个空的初始化列表。这是符合标准的东西,还是编译器错误?我在Fedora 25上使用g ++ 6.4.1。
#include <cstdio>
template<class T> struct pred1 {
constexpr static bool value = false;
};
struct pred2 {
constexpr static bool value = false;
};
template<class A> struct align {
// this assertion only fails with align<int> x; but not with align<int> x();
static_assert( pred1<A>::value == true, "fail1" );
// this assertion will fail anyway
// static_assert( pred2::value == true, "fail2" );
};
int main() {
align<int> x; // this fails
align<int> x {}; // this fails too
align<int> x(); // this does not fail
return 0;
}