re PR c++/40013 (ICE when creating a local array with size from the return value...
authorJakub Jelinek <jakub@redhat.com>
Tue, 5 May 2009 06:37:05 +0000 (08:37 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 5 May 2009 06:37:05 +0000 (08:37 +0200)
PR c++/40013
* pt.c (tsubst): If magic NOP_EXPR with side-effects has no type,
set it from its operand's type after tsubst_expr.

* g++.dg/ext/vla7.C: New test.

From-SVN: r147119

gcc/cp/ChangeLog
gcc/cp/pt.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/vla7.C [new file with mode: 0644]

index 4a34132fe3318325d8e87d85b2ae1e272de1729b..808f0b01433dfc7efabb0fac4f650e51522c5b98 100644 (file)
@@ -1,3 +1,9 @@
+2009-05-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/40013
+       * pt.c (tsubst): If magic NOP_EXPR with side-effects has no type,
+       set it from its operand's type after tsubst_expr.
+
 2009-05-04  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
 
        PR c++/28152
index 4844333770d5a5db71b9fac1d4770801616eda0b..adea7eb46ef3ee6ed1eb55f722872db9d3d1894d 100644 (file)
@@ -9182,6 +9182,14 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
 
        max = tsubst_expr (omax, args, complain, in_decl,
                           /*integral_constant_expression_p=*/false);
+
+       /* Fix up type of the magic NOP_EXPR with TREE_SIDE_EFFECTS if
+          needed.  */
+       if (TREE_CODE (max) == NOP_EXPR
+           && TREE_SIDE_EFFECTS (omax)
+           && !TREE_TYPE (max))
+         TREE_TYPE (max) = TREE_TYPE (TREE_OPERAND (max, 0));
+
        max = fold_decl_constant_value (max);
 
        /* If we're in a partial instantiation, preserve the magic NOP_EXPR
index 6c8d1d2d4c0e1f772878b7a401dc15944b66fa2e..bf5888a1f705cffa7a4d3dc76259decbe8e31417 100644 (file)
@@ -1,3 +1,8 @@
+2009-05-05  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/40013
+       * g++.dg/ext/vla7.C: New test.
+
 2009-05-04  Joseph Myers  <joseph@codesourcery.com>
 
        * gcc.dg/ucnid-11.c, gcc.dg/ucnid-12.c, gcc.dg/ucnid-13.c: New
diff --git a/gcc/testsuite/g++.dg/ext/vla7.C b/gcc/testsuite/g++.dg/ext/vla7.C
new file mode 100644 (file)
index 0000000..5246f9c
--- /dev/null
@@ -0,0 +1,30 @@
+// PR c++/40013
+// { dg-options "" }
+
+template <class T>
+struct A
+{
+  struct B
+  {
+    struct
+    {
+      int fn () { return 0; }
+    } b;
+  };
+  void test ();
+};
+
+template <class T>
+void
+A <T>::test ()
+{
+  B a;
+  int vla[a.b.fn ()];
+}
+
+int
+main ()
+{
+  A <char> a;
+  a.test ();
+}