我在使用 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 failed due to requirement 'std::is_member_function_pointer::value' "A::member is not a member function." static_assert(std::is_member_function_pointer::value, ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated.
如果我删除 noexcept
限定条件,它会按预期进行编译。
这已经在 Debian Stretch 上使用 clang 6.0 和 libstdc++ 6.3.0 进行了测试 我在这里错过了什么吗?据我所知,这应该有效。
最佳答案
您的代码 compiles on GodBolt - 成员有和没有 noexcept
- 有所有 MSVC 2017、GCC 5.5、6.x、8.x、clang 5、6、7。
在我的 Debian Stretch 上(嗯,对应的 Devuan 真的)——我可以重现这个问题。有趣的是,即使我切换到 libc++,编译也会失败。
所以:
- 这不是 clang-6 本身的错误
- 这不是 libstdc++ 6.3.0 本身的错误
- 这可能与 Debian Stretch 的配置/设置方式有关。我建议在 irc.freenode.net 的#debian channel 上提出这个问题
关于c++ - std::is_member_function_pointer 不适用于 noexcept 成员函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54445057/