This was simple enough to backport even though it's concepts.

gcc/cp/ChangeLog
2020-03-05  Jason Merrill  <ja...@redhat.com>

        PR c++/88395
        PR c++/93551
        * constraint.cc (constraints_satisfied_p): Use push_tinst_level.
---
 gcc/cp/constraint.cc                          |  4 ++++
 .../g++.dg/concepts/concepts-pr88395.C        | 23 +++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/concepts/concepts-pr88395.C

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index 9884eb0db50..cbd9c141809 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2390,7 +2390,11 @@ constraints_satisfied_p (tree decl)
       ci = get_constraints (decl);
     }
 
+  if (!push_tinst_level (decl))
+    return true;
   tree eval = satisfy_associated_constraints (ci, args);
+  pop_tinst_level ();
+
   return eval == boolean_true_node;
 }
 
diff --git a/gcc/testsuite/g++.dg/concepts/concepts-pr88395.C 
b/gcc/testsuite/g++.dg/concepts/concepts-pr88395.C
new file mode 100644
index 00000000000..da5834bcc07
--- /dev/null
+++ b/gcc/testsuite/g++.dg/concepts/concepts-pr88395.C
@@ -0,0 +1,23 @@
+// { dg-options "-std=c++17 -fconcepts" }
+
+template <class T, class U>
+concept Concept2 = requires (T t, U u)
+{
+    t += u; // { dg-error "template instantiation depth" }
+};
+
+template <class T>
+concept Concept = Concept2 <T, T>;
+
+struct S
+{
+    template <Concept T>
+    constexpr S& operator += (T o);
+};
+
+constexpr S operator * (S a, S b)
+{
+    return a += b;
+}
+
+// { dg-prune-output "compilation terminated" }

base-commit: 128418afd7ee1bad9185eb88a6e224c2faf90792
-- 
2.18.1

Reply via email to