Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk/14 and perhaps 13?
Alternatively we can set current_template_parms from weakly_subsumes instead, who has only one caller anyway. -- >8 -- Here we normalize the constraint same_as<auto, bool> for the first time during constraint subsumption checking of B / TT as part of ttp coercion. During this normalization the set of in-scope template parameters i.e. current_template_parms is empty, which tricks the satisfaction cache into thinking that the satisfaction value of the constraint is independent of its template parameters, and we incorrectly conflate the satisfaction value with auto = bool vs auto = long and accept the specialization A<long, B>. This patch fixes this by setting current_template_parms appropirately during subsumption checking. PR c++/115656 gcc/cp/ChangeLog: * pt.cc (is_compatible_template_arg): Set current_template_parms around the call to weakly_subsumes. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-ttp7.C: New test. --- gcc/cp/pt.cc | 4 ++++ gcc/testsuite/g++.dg/cpp2a/concepts-ttp7.C | 12 ++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-ttp7.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 017cc7fd0ab..1f6553790a5 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -8493,6 +8493,10 @@ is_compatible_template_arg (tree parm, tree arg, tree args) return false; } + /* Normalization needs to know the effective set of in-scope + template parameters. */ + auto ctp = make_temp_override (current_template_parms, + DECL_TEMPLATE_PARMS (arg)); return weakly_subsumes (parm_cons, arg); } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ttp7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ttp7.C new file mode 100644 index 00000000000..bc123ecf75e --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ttp7.C @@ -0,0 +1,12 @@ +// PR c++/115656 +// { dg-do compile { target c++20 } } + +template<class T, class U> concept same_as = __is_same(T, U); + +template<same_as<bool> U, template<same_as<bool>> class TT> +struct A { }; + +template<same_as<bool>> class B; + +A<bool, B> a1; +A<long, B> a2; // { dg-error "constraint failure" } -- 2.45.2.746.g06e570c0df