]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: always check arity before deduction
authorPatrick Palka <ppalka@redhat.com>
Mon, 18 Sep 2023 18:41:05 +0000 (14:41 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 18 Sep 2023 18:41:05 +0000 (14:41 -0400)
commit155178ccb5f5bc89dcc8261ae1b64bc2fbfdbd45
treeac09e48c3e89d129d4db7115cc5455cb9e389545
parent47346acb72b50d178dae72393c851d57beec383f
c++: always check arity before deduction

This simple patch extends the r12-3271-gf1e73199569287 optimization
to happen for deduction without explicit template arguments as well.
The motivation for this is to accept testcases such as conv20.C and
ttp40.C below, which don't use explicit template arguments but for
which unnecessary template instantiation during deduction could be
avoided if we uniformly pruned overloads according to arity early.
This incidentally causes us to accept one reduced testcase from
PR c++/84075, but the underlying issue there remains at large.

As a nice side effect, this change causes the "candidate expects N
argument(s)" note during overload resolution failure to point to the
template candidate instead of the call site, which seems like an
improvement along the lines of r14-309-g14e881eb030509.

gcc/cp/ChangeLog:

* call.cc (add_template_candidate_real): Check arity even
when there are no explicit template arguments.  Combine the
two adjacent '!obj' tests into one.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/vt-57397-1.C: Expect "candidate expects ... N
argument(s)" at the declaration site instead of the call site.
* g++.dg/cpp0x/vt-57397-2.C: Likewise.
* g++.dg/overload/template5.C: Likewise.
* g++.dg/template/local6.C: Likewise.
* g++.dg/template/conv20.C: New test.
* g++.dg/template/ttp40.C: New test.
gcc/cp/call.cc
gcc/testsuite/g++.dg/cpp0x/vt-57397-1.C
gcc/testsuite/g++.dg/cpp0x/vt-57397-2.C
gcc/testsuite/g++.dg/overload/template5.C
gcc/testsuite/g++.dg/template/conv20.C [new file with mode: 0644]
gcc/testsuite/g++.dg/template/local6.C
gcc/testsuite/g++.dg/template/ttp40.C [new file with mode: 0644]