Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::is_member_function_pointer not working for noexcept member functions

Tags:

c++

c++17

I am having trouble with std::is_member_function_pointer. As far as I can tell, it's not working when given a noexcept member function. I cannot find anything in the standard declaring that it does not work for noexcept qualified member functions. Example of the problem:

#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."); 
}

It gives me the following error:

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.

If I remove the noexcept qualification it compiles as it should.

This has been tested on Debian Stretch, using clang 6.0 and libstdc++ 6.3.0 Am I missing something here? From what I can read, this should work.

like image 857
Martijn Otto Avatar asked Jan 30 '19 16:01

Martijn Otto


1 Answers

Your code compiles on GodBolt - with and without noexcept on the member - with all of MSVC 2017, GCC 5.5, 6.x, 8.x , clang 5, 6, 7.

On my Debian Stretch (well, the corresponding Devuan really) - I can reproduce the issue. Interestingly, compilation fails even if I switch to libc++.

So:

  • This is not a bug in clang-6 in-and-of-itself
  • This is not a libstdc++ 6.3.0 bug in-and-of-itself
  • It might have something to do with the way things were configured/set up for Debian Stretch. I suggest bringing this up on the #debian channel on irc.freenode.net
like image 70
einpoklum Avatar answered Nov 15 '22 21:11

einpoklum