In the testcase below, we never substitute function-template arguments into f15<int>'s placeholder-return-type constraint, which leads to us incorrectly rejecting this instantiation in do_auto_deduction due to satisfaction failure (of the constraint SameAs<int, decltype(x)>).
The fact that we incorrectly reject this testcase is masked by the other instantiation f15<char>, which we correctly reject and diagnose (by accident). A good place to do this missing substitution seems to be during TEMPLATE_TYPE_PARM level lowering. So this patch adds a call to tsubst_constraint there, and also adds dg-bogus directives to this testcase wherever we expect instantiation to succeed. (So without the substitution fix, this last dg-bogus would FAIL). Successfully tested on x86_64-pc-linux-gnu, and also on the cmcstl2 and range-v3 projects. Does this look OK to commit? gcc/cp/ChangeLog: PR c++/96443 * pt.c (tsubst) <case TEMPLATE_TYPE_PARM>: Substitute into the constraints on a placeholder type when its level. gcc/testsuite/ChangeLog: PR c++/96443 * g++.dg/cpp2a/concepts-ts1.C: Add dg-bogus wherever we expect instantiation to succeed. --- gcc/cp/pt.c | 7 ++++--- gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e7496002c1c..04bf6da0cdd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15524,10 +15524,11 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) { - /* Propagate constraints on placeholders since they are - only instantiated during satisfaction. */ + /* Substitute constraints on placeholder when reducing + their level. */ if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (t)) - PLACEHOLDER_TYPE_CONSTRAINTS (r) = constr; + PLACEHOLDER_TYPE_CONSTRAINTS (r) + = tsubst_constraint (constr, args, complain, in_decl); else if (tree pl = CLASS_PLACEHOLDER_TEMPLATE (t)) { pl = tsubst_copy (pl, args, complain, in_decl); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C index 1cefe3b243f..1a9b71c2296 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C @@ -34,13 +34,13 @@ auto f15(auto x) -> SameAs<decltype(x)> { return 0; } // { dg-error "deduced ret void driver() { - f1(0); + f1(0); // { dg-bogus "" } f2(0); // { dg-error "" } - f3(0); + f3(0); // { dg-bogus "" } f3('a'); // { dg-error "" } - f4(0, 0); + f4(0, 0); // { dg-bogus "" } f4(0, 'a'); // { dg-error "" } - f15(0); + f15(0); // { dg-bogus "" } f15('a'); // { dg-message "" } } -- 2.28.0.89.g85b4e0a6dc