]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Avoid ICE on infinite recursion with concepts.
authorJason Merrill <jason@redhat.com>
Thu, 5 Mar 2020 18:45:38 +0000 (13:45 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 5 Mar 2020 19:13:24 +0000 (14:13 -0500)
This was simple enough to backport even though it's concepts.

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

PR c++/88395
PR c++/93551
* constraint.cc (constraints_satisfied_p): Use push_tinst_level.

gcc/cp/ChangeLog
gcc/cp/constraint.cc
gcc/testsuite/g++.dg/concepts/concepts-pr88395.C [new file with mode: 0644]

index 437df4d0829a184457d32e84cc5d7eca4c79edaa..c697ff3a442191b9e90369bfe8b97d685253225f 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-05  Jason Merrill  <jason@redhat.com>
+
+       PR c++/88395
+       PR c++/93551
+       * constraint.cc (constraints_satisfied_p): Use push_tinst_level.
+
 2020-03-05  Martin Sebor  <msebor@redhat.com>
 
        Backport from trunk.
index 9884eb0db50e48cf9cca5a8af9f32ff8db3a686b..cbd9c141809b8849a21379c043ba6b2eff866c39 100644 (file)
@@ -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 (file)
index 0000000..da5834b
--- /dev/null
@@ -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" }