https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83137

            Bug ID: 83137
           Summary: Member function pointer template parameter not
                    constant expression when set to nullptr
           Product: gcc
           Version: 7.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: erik2003 at u dot washington.edu
  Target Milestone: ---

Created attachment 42700
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42700&action=edit
minimal bug example with additional context

When using if constexpr(), GCC claims a member function pointer template
parameter isn't a constant expression if set to nullptr. This does not happen
if the member function pointer points to a real function, or if a raw function
pointer is used instead. Replacing nullptr with (void (Fake::*)())0 or (void
(Fake::*)())NULL produces the same error.

This code compiles in clang but generates an error in GCC:

struct Fake { };

template<class T, void (T::*SET)()>
void MemberTest()
{
  if constexpr(SET == nullptr)
    return;
}

int main()
{
  MemberTest<Fake, nullptr>();
}

gccbug.cpp: In instantiation of ‘void MemberTest() [with T = Fake; void (T::*
SET)() = void (Fake::*)(){0, 0}]’:
gccbug.cpp:20:29:   required from here
gccbug.cpp:6:20: error: ‘(void (Fake::*)(){0, 0}.void (Fake::*)()::__pfn == 0)’
is not a constant expression
   if constexpr(SET == nullptr)
                ~~~~^~~~~~~~~~

This was tested on GCC 7.1.1 and 7.2.0, and is similar to Bug 56428, but
applies to member function pointers only and is triggered by setting the member
function pointer to nullptr instead of comparing it to nullptr.

Reply via email to