【发布时间】:2019-01-30 16:22:33
【问题描述】:
我在使用 std::is_member_function_pointer 时遇到问题。据我所知,当给定 noexcept 成员函数时它不起作用。我在标准中找不到任何声明它不适用于noexcept 合格成员函数的内容。问题示例:
#include <type_traits>
class A {
public:
void member() noexcept { }
};
int main()
{
// fails at compile time if A::member is a data member and not a function
static_assert(std::is_member_function_pointer<decltype(&A::member)>::value,
"A::member is not a member function.");
}
它给了我以下错误:
member.cpp:11:5: error: static_assert 由于要求而失败 'std::is_member_function_pointer::value' "A::member 不是成员函数。" static_assert(std::is_member_function_pointer::value, ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~ 1个错误 生成。
如果我删除 noexcept 限定符,它将按应有的方式编译。
这已经在 Debian Stretch 上使用 clang 6.0 和 libstdc++ 6.3.0 进行了测试 我在这里错过了什么吗?据我所知,这应该工作。
【问题讨论】:
-
你试过用 libcxx 代替吗?也许只是实现中的一个错误?
-
适用于 gcc 8.2 和 clang 7。
-
好吧,有趣的是,安装 libc++-dev 并使用它进行编译并没有帮助,但它可能是 repo (3.5.2) 中的一个非常旧的版本。似乎它只在启用 c++17 时才会中断,但在 c++14 模式下它可以工作。一定是我的 libstdc++ 版本还没有更新,因为在 c++17 中 noexcept 是类型系统的一部分。
-
我认为这是一个相关的错误:Function pointer conversion with noexcept fails