From: Jason Merrill Date: Tue, 12 Jun 2012 18:32:04 +0000 (-0400) Subject: re PR c++/53599 (gcc-4.7.1_rc20120606 segfaults compiling boost.karma) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=fdaf2f48c02dcb5dcf9bbca130b2de56fc947f75;p=gcc.git re PR c++/53599 (gcc-4.7.1_rc20120606 segfaults compiling boost.karma) PR c++/53599 * name-lookup.c (pushtag_1): Add a DECL_EXPR for a local class. * semantics.c (finish_cond): Build a COMPOUND_EXPR. * pt.c (tsubst_expr) [COMPOUND_EXPR]: Handle. [DECL_EXPR]: Don't call cp_finish_decl for an implicit typedef. Don't return the decl. From-SVN: r188473 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 29c721fb7bf..203955e3bc7 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,12 @@ +2012-06-09 Jason Merrill + + PR c++/53599 + * name-lookup.c (pushtag_1): Add a DECL_EXPR for a local class. + * semantics.c (finish_cond): Build a COMPOUND_EXPR. + * pt.c (tsubst_expr) [COMPOUND_EXPR]: Handle. + [DECL_EXPR]: Don't call cp_finish_decl for an implicit typedef. + Don't return the decl. + 2012-06-11 Richard Guenther PR c++/53605 diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c index 9cc6d39fffa..0f2882044c7 100644 --- a/gcc/cp/name-lookup.c +++ b/gcc/cp/name-lookup.c @@ -5796,7 +5796,16 @@ pushtag_1 (tree name, tree type, tag_scope scope) class.) */ if (TYPE_CONTEXT (type) && TREE_CODE (TYPE_CONTEXT (type)) == FUNCTION_DECL) - VEC_safe_push (tree, gc, local_classes, type); + { + if (processing_template_decl) + { + /* Push a DECL_EXPR so we call pushtag at the right time in + template instantiation rather than in some nested context. */ + add_decl_expr (decl); + } + else + VEC_safe_push (tree, gc, local_classes, type); + } } if (b->kind == sk_class && !COMPLETE_TYPE_P (current_class_type)) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index df80159cf75..04f7be81f3e 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12887,6 +12887,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, DECL_CONTEXT (decl) = current_function_decl; insert_capture_proxy (decl); } + else if (DECL_IMPLICIT_TYPEDEF_P (t)) + /* We already did a pushtag. */; else { int const_init = false; @@ -12930,9 +12932,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, } } - /* A DECL_EXPR can also be used as an expression, in the condition - clause of an if/for/while construct. */ - return decl; + break; } case FOR_STMT: @@ -13341,6 +13341,15 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, error ("use %<...%> to expand argument pack"); return error_mark_node; + case COMPOUND_EXPR: + tmp = RECUR (TREE_OPERAND (t, 0)); + if (tmp == NULL_TREE) + /* If the first operand was a statement, we're done with it. */ + return RECUR (TREE_OPERAND (t, 1)); + return build_x_compound_expr (EXPR_LOCATION (t), tmp, + RECUR (TREE_OPERAND (t, 1)), + complain); + default: gcc_assert (!STATEMENT_CODE_P (TREE_CODE (t))); diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 7769bbaa36f..f8ad2a5884a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -509,11 +509,14 @@ finish_cond (tree *cond_p, tree expr) if (processing_template_decl) { tree cond = pop_stmt_list (*cond_p); - if (TREE_CODE (cond) == DECL_EXPR) - expr = cond; - if (check_for_bare_parameter_packs (expr)) - *cond_p = error_mark_node; + if (expr == NULL_TREE) + /* Empty condition in 'for'. */ + gcc_assert (empty_expr_stmt_p (cond)); + else if (check_for_bare_parameter_packs (expr)) + expr = error_mark_node; + else if (!empty_expr_stmt_p (cond)) + expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr); } *cond_p = expr; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 953ccb90814..908e25b07fc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-06-07 Jason Merrill + + PR c++/53599 + * g++.dg/template/local7.C: New. + 2012-06-12 Oleg Endo PR target/53511 diff --git a/gcc/testsuite/g++.dg/template/local7.C b/gcc/testsuite/g++.dg/template/local7.C new file mode 100644 index 00000000000..3045534eaa6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/local7.C @@ -0,0 +1,15 @@ +// PR c++/53599 + +template +int foo () +{ + struct F; + struct G + { + static int F::* bar(); + }; + + return sizeof(G); +} + +int z = foo ();