diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4a34132fe33..808f0b01433 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2009-05-05 Jakub Jelinek + + 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 PR c++/28152 diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 4844333770d..adea7eb46ef 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6c8d1d2d4c0..bf5888a1f70 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-05-05 Jakub Jelinek + + PR c++/40013 + * g++.dg/ext/vla7.C: New test. + 2009-05-04 Joseph Myers * 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 index 00000000000..5246f9c8c38 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vla7.C @@ -0,0 +1,30 @@ +// PR c++/40013 +// { dg-options "" } + +template +struct A +{ + struct B + { + struct + { + int fn () { return 0; } + } b; + }; + void test (); +}; + +template +void +A ::test () +{ + B a; + int vla[a.b.fn ()]; +} + +int +main () +{ + A a; + a.test (); +}