]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: constrained memfn vs corresponding using [PR121351]
authorPatrick Palka <ppalka@redhat.com>
Mon, 4 Aug 2025 20:51:00 +0000 (16:51 -0400)
committerPatrick Palka <ppalka@redhat.com>
Mon, 4 Aug 2025 20:51:00 +0000 (16:51 -0400)
commitb9f1cc4e119da9205cb8438f0132c62a19afe4ae
tree4ba6a78e7add8209b49d746bbde824bdac16bcce
parentb51ca7d2f548ffdad03fa779e3ff7bcc3441ff03
c++: constrained memfn vs corresponding using [PR121351]

The b.f(42) calls in the below testcases started to get rejected as
ambiguous after r15-3740 which corrected our inheritedness tiebreaker to
only apply to constructors (and not all member functions) as per CWG2273.

But arguably these calls should still be valid regardless of the
tiebreaker because B::f corresponds to and therefore hides A::f, so
there should only be a single candidate in the first place.  This
doesn't happen because when determining correspondence we compare
the members' uninstantiated constraints instead of their partially
substituted constraints as in other declaration matching situations.
It doesn't really make sense to compare uninstantiated constraints
from two different template contexts.

This patch fixes this by substituting in outer template arguments before
comparing constraints of two potentially corresponding member functions.

PR c++/121351
PR c++/119859

gcc/cp/ChangeLog:

* class.cc (add_method): Substitute outer template arguments
into constraints before comparing them if the declarations are
from different classes.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/concepts-using5.C: New test.
* g++.dg/cpp2a/concepts-using5a.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/class.cc
gcc/testsuite/g++.dg/cpp2a/concepts-using5.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp2a/concepts-using5a.C [new file with mode: 0644]