]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: cp_stabilize_reference and non-dep exprs [PR111919]
authorPatrick Palka <ppalka@redhat.com>
Tue, 24 Oct 2023 21:48:00 +0000 (17:48 -0400)
committerPatrick Palka <ppalka@redhat.com>
Tue, 24 Oct 2023 21:48:00 +0000 (17:48 -0400)
After the removal of NON_DEPENDENT_EXPR, cp_stabilize_reference (which
used to just exit early for NON_DEPENDENT_EXPR) is now more prone to
passing a weird templated tree to middle-end routines, which for the
testcase below leads to a crash from contains_placeholder_p.  It seems
the best fix is to just exit early when in a template context, like we
do in the closely related function cp_save_expr.

PR c++/111919

gcc/cp/ChangeLog:

* tree.cc (cp_stabilize_reference): Do nothing when
processing_template_decl.

gcc/testsuite/ChangeLog:

* g++.dg/template/non-dependent27.C: New test.

gcc/cp/tree.cc
gcc/testsuite/g++.dg/template/non-dependent27.C [new file with mode: 0644]

index a3d61d3e7c985aa4ea9b962b480e786aa7ea7768..417c92ba76fc8d3c6ead2476878b35e68b834416 100644 (file)
@@ -408,6 +408,10 @@ bitfield_p (const_tree ref)
 tree
 cp_stabilize_reference (tree ref)
 {
+  if (processing_template_decl)
+    /* As in cp_save_expr.  */
+    return ref;
+
   STRIP_ANY_LOCATION_WRAPPER (ref);
   switch (TREE_CODE (ref))
     {
diff --git a/gcc/testsuite/g++.dg/template/non-dependent27.C b/gcc/testsuite/g++.dg/template/non-dependent27.C
new file mode 100644 (file)
index 0000000..c06bca7
--- /dev/null
@@ -0,0 +1,8 @@
+// PR c++/111919
+
+int i[42];
+
+template<class T>
+void f() {
+  i[42 / (int)sizeof(T)] |= 42;
+}