public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: ICE with template NEW_EXPR [PR105803]
@ 2022-06-01 22:45 Marek Polacek
  2022-06-02 12:42 ` Patrick Palka
  0 siblings, 1 reply; 8+ messages in thread
From: Marek Polacek @ 2022-06-01 22:45 UTC (permalink / raw)
  To: Jason Merrill, GCC Patches

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.

Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?

	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                          |  8 ++++++++
 gcc/testsuite/g++.dg/template/new13.C | 11 +++++++++++
 2 files changed, 19 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/template/new13.C

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 6de8e496859..836861e1039 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -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
index 00000000000..3168374b26d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/new13.C
@@ -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);
+}

base-commit: 2d546ff69455f7deadab65309de89d19380a8864
-- 
2.36.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-06-02 20:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-01 22:45 [PATCH] c++: ICE with template NEW_EXPR [PR105803] Marek Polacek
2022-06-02 12:42 ` Patrick Palka
2022-06-02 14:03   ` Marek Polacek
2022-06-02 19:42     ` Jason Merrill
2022-06-02 20:10       ` Marek Polacek
2022-06-02 20:26         ` Jason Merrill
2022-06-02 20:33           ` Marek Polacek
2022-06-02 20:38             ` Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).