]> 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>
Fri, 8 Aug 2025 14:01:43 +0000 (10:01 -0400)
commit9faa21a4de2b88366e363b6817ee751ea8d13f53
tree6999b1c52e868c026e30e09d416493008d3927c6
parentb3893433abd8d3a4096f8c51d028115d461fe6aa
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>
(cherry picked from commit b9f1cc4e119da9205cb8438f0132c62a19afe4ae)
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]