]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE with template NEW_EXPR [PR105803]
authorMarek Polacek <polacek@redhat.com>
Wed, 1 Jun 2022 22:21:36 +0000 (18:21 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 2 Jun 2022 20:00:45 +0000 (16:00 -0400)
Here we ICE because value_dependent_expression_p gets a NEW_EXPR
whose operand is a type, and we go to the default case which just
calls v_d_e_p on each operand of the NEW_EXPR.  Since one of them
is a type, we crash on the new assert in t_d_e_p.

t_d_e_p has code to handle {,VEC_}NEW_EXPR, which at this point
was already performed, so I think we can handle these two codes
specifically and skip the second operand, which is always going
to be a type.

PR c++/105803

gcc/cp/ChangeLog:

* pt.cc (value_dependent_expression_p): Handle {,VEC_}NEW_EXPR
in the switch.

gcc/testsuite/ChangeLog:

* g++.dg/template/new13.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/template/new13.C [new file with mode: 0644]

index 6de8e496859acd92d92b02141f974f743d7b7303..836861e10391e0e16248724ab9ba4d20f4849387 100644 (file)
@@ -27643,6 +27643,14 @@ value_dependent_expression_p (tree expression)
         under instantiate_non_dependent_expr; it can't be constant.  */
       return true;
 
+    case NEW_EXPR:
+    case VEC_NEW_EXPR:
+      /* The second operand is a type, which type_dependent_expression_p
+        (and therefore value_dependent_expression_p) doesn't want to see.  */
+      return (value_dependent_expression_p (TREE_OPERAND (expression, 0))
+             || value_dependent_expression_p (TREE_OPERAND (expression, 2))
+             || value_dependent_expression_p (TREE_OPERAND (expression, 3)));
+
     default:
       /* A constant expression is value-dependent if any subexpression is
         value-dependent.  */
diff --git a/gcc/testsuite/g++.dg/template/new13.C b/gcc/testsuite/g++.dg/template/new13.C
new file mode 100644 (file)
index 0000000..17a19e4
--- /dev/null
@@ -0,0 +1,11 @@
+// PR c++/105803
+// { dg-do compile }
+// { dg-additional-options "-fchecking=2" }
+
+namespace std {
+template <typename> class shared_ptr {};
+}
+struct S {};
+template <int> void build_matrices() {
+  std::shared_ptr<S>(new S);
+}