diff mbox series

[COMMITTED] c++: Fix error-recovery with concepts.

Message ID 20200204230848.16649-1-jason@redhat.com
State New
Headers show
Series [COMMITTED] c++: Fix error-recovery with concepts. | expand

Commit Message

Jason Merrill Feb. 4, 2020, 11:08 p.m. UTC
Here, push_tinst_level refused to push into the scope of Foo::Foo
because it was triggered from the ill-formed function fun.  But we didn't
check the return value and tried to pop the un-pushed level.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/93551
	* constraint.cc (satisfy_declaration_constraints): Check return
	value of push_tinst_level.
---
 gcc/cp/constraint.cc                       |  3 +-
 gcc/testsuite/g++.dg/cpp2a/concepts-err1.C | 33 ++++++++++++++++++++++
 2 files changed, 35 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-err1.C


base-commit: 0712ea6313bc44f9ae8feb235c1b02c92cdd0527
diff mbox series

Patch

diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc
index cda644eabe2..58044cd0f9d 100644
--- a/gcc/cp/constraint.cc
+++ b/gcc/cp/constraint.cc
@@ -2692,7 +2692,8 @@  satisfy_declaration_constraints (tree t, subst_info info)
   tree result = boolean_true_node;
   if (norm)
     {
-      push_tinst_level (t);
+      if (!push_tinst_level (t))
+	return result;
       push_access_scope (t);
       result = satisfy_associated_constraints (norm, args, info);
       pop_access_scope (t);
diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-err1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-err1.C
new file mode 100644
index 00000000000..e482ba05b46
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/concepts-err1.C
@@ -0,0 +1,33 @@ 
+// PR c++/93551
+// { dg-do compile { target concepts } }
+
+namespace std {
+  template<typename _Tp, _Tp __v>
+  struct integral_constant
+  {
+    static constexpr _Tp                  value = __v;
+    typedef _Tp                           value_type;
+    typedef integral_constant<_Tp, __v>   type;
+    constexpr operator value_type() const noexcept { return value; }
+  };
+  template<typename _Base, typename _Derived>
+  struct is_base_of
+    : public integral_constant<bool, __is_base_of(_Base, _Derived)>
+  { };
+  template <typename _Base, typename _Derived>
+  inline constexpr bool is_base_of_v = is_base_of<_Base, _Derived>::value;
+}
+class Bar { };
+struct Foo {
+  template <typename P> requires std::is_base_of_v<Bar, P>
+  Foo(P const&);
+};
+template <typename P>
+Foo fun(P const& arg) {
+  (bool)arg;			// { dg-error "" }
+  return Foo {arg};
+}
+int main() {
+  fun(Bar{});
+  return 0;
+}