From: Patrick Palka Date: Wed, 13 Dec 2023 20:55:01 +0000 (-0500) Subject: c++: unifying FUNCTION_DECLs [PR93740] X-Git-Tag: basepoints/gcc-15~3620 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c822ad86984e752734b9c371f9cfef9330334ec4;p=thirdparty%2Fgcc.git c++: unifying FUNCTION_DECLs [PR93740] unify currently always returns success when unifying two FUNCTION_DECLs (due to the is_overloaded_fn deferment within the default case), which means for the below testcase we incorrectly unify &A::foo and &A::bar leading to deduction failure for the index_of calls due to a bogus base class ambiguity. This patch makes unify handle FUNCTION_DECL naturally like other decls. PR c++/93740 gcc/cp/ChangeLog: * pt.cc (unify) : Handle it like FIELD_DECL and TEMPLATE_DECL. gcc/testsuite/ChangeLog: * g++.dg/template/ptrmem34.C: New test. --- diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 0dd0a9c644c1..9a21467bf219 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -24964,6 +24964,7 @@ unify (tree tparms, tree targs, tree parm, tree arg, int strict, gcc_unreachable (); case FIELD_DECL: + case FUNCTION_DECL: case TEMPLATE_DECL: /* Matched cases are handled by the ARG == PARM test above. */ return unify_template_argument_mismatch (explain_p, parm, arg); diff --git a/gcc/testsuite/g++.dg/template/ptrmem34.C b/gcc/testsuite/g++.dg/template/ptrmem34.C new file mode 100644 index 000000000000..75c911ee243c --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ptrmem34.C @@ -0,0 +1,27 @@ +// PR c++/93740 +// { dg-do compile { target c++11 } } + +struct A { + void foo(); + void bar(); +}; + +template +struct const_val { }; + +template +struct indexed_elem { }; + +using mem_fun_A_foo = const_val; +using mem_fun_A_bar = const_val; + +struct A_indexed_member_funcs + : indexed_elem<0, mem_fun_A_foo>, + indexed_elem<1, mem_fun_A_bar> +{ }; + +template +constexpr int index_of(indexed_elem) { return N; } + +static_assert(index_of(A_indexed_member_funcs{}) == 0, ""); +static_assert(index_of(A_indexed_member_funcs{}) == 1, "");