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.
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))
{
--- /dev/null
+// PR c++/111919
+
+int i[42];
+
+template<class T>
+void f() {
+ i[42 / (int)sizeof(T)] |= 42;
+}