From 5bbca03966e06a79f5dd06166f6998369256efa9 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 5 May 2009 08:37:05 +0200 Subject: [PATCH] re PR c++/40013 (ICE when creating a local array with size from the return value of a member function of an object in a nested class in a template class) 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 | 6 ++++++ gcc/cp/pt.c | 8 ++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/vla7.C | 30 ++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/vla7.C 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 (); +}