public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: dependent constraint on placeholder return type [PR96443]
@ 2020-08-04 19:22 Patrick Palka
  2020-08-05  0:00 ` Patrick Palka
  0 siblings, 1 reply; 5+ messages in thread
From: Patrick Palka @ 2020-08-04 19:22 UTC (permalink / raw)
  To: gcc-patches

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-08-10 18:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-04 19:22 [PATCH] c++: dependent constraint on placeholder return type [PR96443] Patrick Palka
2020-08-05  0:00 ` Patrick Palka
2020-08-05 19:46   ` Jason Merrill
2020-08-06 13:47     ` Patrick Palka
2020-08-10 18:51       ` Patrick Palka

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).