【发布时间】:2015-11-09 18:33:55
【问题描述】:
考虑以下情况
typedef void (*foo)();
template<foo f>
struct bar {
static_assert(f!=nullptr,"f == null!");
};
void baz() {}
inline void bax() { }
bar<baz> ok;
bar<bax> bad; // error: non-constant condition for static assertion
baz 和 bax 都被接受为模板参数。
它表明两者都被接受为常数。
然而,在static_assert 他们似乎是不同的(至少在 gcc 4.9 中) - bax 不再是一个常数。
我的假设是static_assert 和模板评估恒定性相同。
例如。任何一个错误都应该是
- 'bax 不是有效的模板参数'或
-
static_assert不应引发非常量条件错误。
我错了吗?
【问题讨论】:
-
除非在某处声明了
foo,否则我希望这根本不会编译... -
@Quentin: 不使用 gcc...coliru.stacked-crooked.com/a/72fd4b666aa73737
-
在 clang++ 3.7 [大约在 3.7-RC1 之前的一两周] 中工作,而不是在 gcc 4.9.2 中。怀疑是gcc的bug。
-
这个GCC bugzilla thread和这个问题有关吗? Clang3.6可以编译bugzilla中的代码,但是gcc5+和gcc6HEAD不行。
标签: c++ function templates inline static-assert