From 303b74068a5667b688d192bc96829989f5bafc9f Mon Sep 17 00:00:00 2001 From: Nathan Sidwell Date: Mon, 18 Aug 2003 12:55:04 +0000 Subject: [PATCH] re PR c++/11957 (wrong "warning: statement has no effect") cp: PR c++/11957 * cp-tree.h (finish_stmt_expr): Add bool parameter. * init.c (finish_init_stmts): Pass true to finish_stmt_expr. Don't adjust the stmt_expr here. (build_vec_init): Use finish_stmt_expr_expr, convert result to array type. * parser.c (cp_parser_primar_expression): Adjust finish_stmt_expr call. * pt.c (tsubst_copy): Likewise. * semantics.c (finish_stmt_expr): Add parameter. testsuite: PR c++/11957 * g++.dg/warn/noeffect1.C: New test. From-SVN: r70541 --- gcc/cp/ChangeLog | 11 +++++++++++ gcc/cp/cp-tree.h | 2 +- gcc/cp/init.c | 25 ++++++++++++++----------- gcc/cp/parser.c | 2 +- gcc/cp/pt.c | 2 +- gcc/cp/semantics.c | 12 ++++++------ 6 files changed, 34 insertions(+), 20 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 19562e612a6..732540ebd19 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,16 @@ 2003-08-18 Nathan Sidwell + PR c++/11957 + * cp-tree.h (finish_stmt_expr): Add bool parameter. + * init.c (finish_init_stmts): Pass true to finish_stmt_expr. Don't + adjust the stmt_expr here. + (build_vec_init): Use finish_stmt_expr_expr, convert result to + array type. + * parser.c (cp_parser_primar_expression): Adjust finish_stmt_expr + call. + * pt.c (tsubst_copy): Likewise. + * semantics.c (finish_stmt_expr): Add parameter. + * pt.c (instantiate_class_template): Push to class's scope before tsubsting base. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index eae862a3380..43655b570f4 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -4102,7 +4102,7 @@ extern tree finish_parenthesized_expr (tree); extern tree finish_non_static_data_member (tree, tree, tree); extern tree begin_stmt_expr (void); extern tree finish_stmt_expr_expr (tree); -extern tree finish_stmt_expr (tree); +extern tree finish_stmt_expr (tree, bool); extern tree perform_koenig_lookup (tree, tree); extern tree finish_call_expr (tree, tree, bool); extern tree finish_increment_expr (tree, enum tree_code); diff --git a/gcc/cp/init.c b/gcc/cp/init.c index c2b371114e3..0cd7270ca37 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -85,9 +85,7 @@ finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt) { finish_compound_stmt (compound_stmt); - stmt_expr = finish_stmt_expr (stmt_expr); - STMT_EXPR_NO_SCOPE (stmt_expr) = true; - TREE_USED (stmt_expr) = 1; + stmt_expr = finish_stmt_expr (stmt_expr, true); my_friendly_assert (!building_stmt_tree () == is_global, 20030726); @@ -2478,7 +2476,7 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array) base = cp_convert (ptype, decay_conversion (base)); /* The code we are generating looks like: - + ({ T* t1 = (T*) base; T* rval = t1; ptrdiff_t iterator = maxindex; @@ -2490,7 +2488,8 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array) } catch (...) { ... destroy elements that were constructed ... } - return rval; + rval; + }) We can omit the try and catch blocks if we know that the initialization will never throw an exception, or if the array @@ -2662,18 +2661,22 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array) finish_compound_stmt (try_body); finish_cleanup_try_block (try_block); - e = build_vec_delete_1 (rval, m, - type, - sfk_base_destructor, + e = build_vec_delete_1 (rval, m, type, sfk_base_destructor, /*use_global_delete=*/0); finish_cleanup (e, try_block); } - /* The value of the array initialization is the address of the - first element in the array. */ - finish_expr_stmt (rval); + /* The value of the array initialization is the array itself, RVAL + is a pointer to the first element. */ + finish_stmt_expr_expr (rval); stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt); + + /* Now convert make the result have the correct type. */ + atype = build_pointer_type (atype); + stmt_expr = build1 (NOP_EXPR, atype, stmt_expr); + stmt_expr = build_indirect_ref (stmt_expr, NULL); + current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps; return stmt_expr; } diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index b485fb5e582..2e5e4dd54ab 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -2270,7 +2270,7 @@ cp_parser_primary_expression (cp_parser *parser, /* Parse the compound-statement. */ cp_parser_compound_statement (parser, true); /* Finish up. */ - expr = finish_stmt_expr (expr); + expr = finish_stmt_expr (expr, false); } else { diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e0dfcb78774..083060329d2 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -7343,7 +7343,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) tsubst_expr (STMT_EXPR_STMT (t), args, complain | tf_stmt_expr_cmpd, in_decl); - return finish_stmt_expr (stmt_expr); + return finish_stmt_expr (stmt_expr, false); } return t; diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 2316392b08a..2997237b06a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -1405,7 +1405,7 @@ begin_stmt_expr (void) last_expr_type = NULL_TREE; keep_next_level (1); - + return last_tree; } @@ -1469,13 +1469,12 @@ finish_stmt_expr_expr (tree expr) return result; } -/* Finish a statement-expression. RTL_EXPR should be the value - returned by the previous begin_stmt_expr; EXPR is the - statement-expression. Returns an expression representing the - statement-expression. */ +/* Finish a statement-expression. EXPR should be the value returned + by the previous begin_stmt_expr. Returns an expression + representing the statement-expression. */ tree -finish_stmt_expr (tree rtl_expr) +finish_stmt_expr (tree rtl_expr, bool has_no_scope) { tree result; tree result_stmt = last_expr_type; @@ -1496,6 +1495,7 @@ finish_stmt_expr (tree rtl_expr) result = build_min (STMT_EXPR, type, last_tree); TREE_SIDE_EFFECTS (result) = 1; + STMT_EXPR_NO_SCOPE (result) = has_no_scope; last_expr_type = NULL_TREE;