GCC 4.9 在检查内联函数的指针时出错(带 static_assert)
GCC 4.9 gives error when checking inline function's pointer (with static_assert)
考虑以下情况
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
不应该引发非恒定条件错误。
我错了吗?
又一个GCC
错误,更新到新版本,或者迁移到LLVM
(clang
)。
详情请参阅问题单:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=52036
内联函数时,指向该函数的指针不存在。因此不能与nullptr进行比较。
函数最终是否内联取决于编译器。inline
关键字不保证。
相关文章:
- 访问者访问变体并返回不同类型时出错
- 在Linux for Windows上编译C++代码时出错
- 读取文件的最后一行并输入到链接列表时出错
- 重载操作程序时出错>>用于类中的字符串 memebr
- 调用专用模板时出错"no matching function for call to [...]"
- C++-试图将函数指针推回到另一个CPP文件中的矢量时出错
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 为什么即使使用-cudart-static进行编译,库用户仍然需要链接到cuda运行时
- 在Google Kick start中提交时出错
- 在c++中访问int到类对象的映射时出错
- 分段错误当我试图运行程序时出错
- 使用dynamic_cast和构造函数时出错
- CHECK(调用)函数在Google Colab中出错
- 用pybind11包装C++抽象类时出错
- 为x86而非x64编译时出错
- 从R调用C++函数并对其进行集成时出错
- 这个函数哪里出错了
- 如何处理 c++ 中类实现中的"invalid use of non-static data member"?
- C++ 创建包含链表和字符串的对象的链接列表时出错
- 在Struct中使用Static时出错