re PR c++/88395 (ICE: Segmentation fault signal terminated program cc1plus, with...
authorAndrew Sutton <asutton@lock3software.com>
Wed, 27 Nov 2019 15:09:22 +0000 (15:09 +0000)
committerAndrew Sutton <asutton@gcc.gnu.org>
Wed, 27 Nov 2019 15:09:22 +0000 (15:09 +0000)
2019-11-27  Andrew Sutton  <asutton@lock3software.com>

PR c++/88395
Prevent recursive satisfaction by adding requests to the instantiation
stack.

gcc/cp/
* constraint.cc (satisfy_declaration_constraints): Push tinst levels
around satisfaction.

gcc/testsuite/
* g++.dg/cpp2a/concepts-pr88395.C: New.
* g++.dg/cpp2a/concepts-recursive-sat1.C: New.
* g++.dg/cpp2a/concepts-recursive-sat2.C: New.
* g++.dg/cpp2a/concepts-recursive-sat3.C: New.

From-SVN: r278773

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

index 5f770e939d8e50620f9babb7ab000bafa0b48ba4..470a5271ded85945291fdc26d13b6be2c57516b0 100644 (file)
@@ -1,3 +1,9 @@
+2019-11-27  Andrew Sutton  <asutton@lock3software.com>
+
+       PR c++/88395
+       * constraint.cc (satisfy_declaration_constraints): Push tinst levels
+       around satisfaction.
+
 2019-11-27  Andrew Sutton  <asutton@lock3software.com>
 
        Diagnose certain constraint errors as hard errors, but otherwise treat
index d29c33a9bbfc24bd7be029a5cc1dba2ef068bebb..9967b1ef996993d6741c925cc89d8d0ba9fe6ea8 100644 (file)
@@ -2648,9 +2648,11 @@ satisfy_declaration_constraints (tree t, subst_info info)
   tree result = boolean_true_node;
   if (norm)
     {
+      push_tinst_level (t);
       push_access_scope (t);
       result = satisfy_associated_constraints (norm, args, info);
       pop_access_scope (t);
+      pop_tinst_level ();
     }
 
   if (info.quiet ())
index 39728cf82ca13efb40e49bbe9edf1e2a72dfd005..8605b0b38fad6a64b815cab04f2ddf050e5d08ba 100644 (file)
@@ -1,3 +1,11 @@
+2019-11-18  Andrew Sutton  <asutton@lock3software.com>
+
+       PR c++/88395
+       * g++.dg/cpp2a/concepts-pr88395.C: New.
+       * g++.dg/cpp2a/concepts-recursive-sat1.C: New.
+       * g++.dg/cpp2a/concepts-recursive-sat2.C: New.
+       * g++.dg/cpp2a/concepts-recursive-sat3.C: New.
+
 2019-11-27  Vladimir Makarov  <vmakarov@redhat.com>
 
        PR rtl-optimization/90007
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-pr88395.C b/gcc/testsuite/g++.dg/cpp2a/concepts-pr88395.C
new file mode 100644 (file)
index 0000000..ad24da9
--- /dev/null
@@ -0,0 +1,23 @@
+// { dg-do compile { target c++2a } }
+
+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" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat1.C
new file mode 100644 (file)
index 0000000..ee83d56
--- /dev/null
@@ -0,0 +1,18 @@
+// { dg-do compile { target c++2a } }
+
+template<int N, typename T>
+concept Foo = requires(T t) { foo<N + 1>(t); }; // { dg-error "template instantiation depth" }
+
+template<int N = 1, typename T = int>
+  requires Foo<N, T>
+int foo(T t)
+{
+  return foo<N + 1>(t);
+}
+
+int main(int, char**)
+{
+  return foo<1>(1);
+}
+
+// { dg-prune-output "compilation terminated" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat2.C
new file mode 100644 (file)
index 0000000..d76f12e
--- /dev/null
@@ -0,0 +1,15 @@
+// { dg-do compile { target c++2a } }
+
+template<typename T>
+concept Fooable = requires(T t) { foo(t); }; // { dg-error "template instantiation depth" }
+
+template<Fooable T>
+void foo(T t) { }
+
+void test()
+{
+  struct S {} s;
+  foo(s);
+}
+
+// { dg-prune-output "compilation terminated" }
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat3.C b/gcc/testsuite/g++.dg/cpp2a/concepts-recursive-sat3.C
new file mode 100644 (file)
index 0000000..b8ca916
--- /dev/null
@@ -0,0 +1,12 @@
+// { dg-do compile { target c++2a } }
+
+template<typename T>
+concept Fooable = requires(T t) { foo(t); };
+
+template<Fooable T>
+void foo(T t) { }
+
+void test()
+{
+  foo(0); // { dg-error "unsatisfied constraints" }
+}