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

            Bug ID: 90338
           Summary: member function pointer non-type template parameter
                    compile fail while matching
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: patrick.a.moran at gmail dot com
  Target Milestone: ---

Created attachment 46280
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46280&action=edit
A reproduction of the issue described

The code in question compiled in 8.3.0, but fails in 9.1.0.

We have two template functions that each take one type template parameter and
one non-type template parameter. The first template function's non-type
template parameter is of a member function type, and the second template
function's non-type template parameter is it's type template parameter. (I
think this is clearer in the reproduction).

If you then call the first template function actually giving it a pointer to a
member function that exactly matches, but the class whose member function it is
is non-literal, you get a compile-failure (error below).

> repro.cpp:13:22: error: ‘B’ is not a valid type for a template non-type 
> parameter because it is not literal
>    13 |   match<B, &B::func>();
>       |                      ^
> repro.cpp:1:8: note: ‘B’ is not literal because:
>     1 | struct B {
>       |        ^
> repro.cpp:1:8: note:   ‘B’ is not an aggregate, does not have a trivial 
> default constructor, and has no ‘constexpr’ constructor that is not a copy or 
> move constructor

It appears that when it considers
  template <class Any, Any Value>
  void match();
as a match, it errors out based on the fact that you _couldn't_ pass your class
type as a non-type template parameter (even though you're making no attempt to
do so). If you make the class trivial so that this error doesn't happen, you
can see that it does choose the correct match().

Reply via email to