Commit 303b7406 by Nathan Sidwell Committed by Nathan Sidwell

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
parent a2507277
2003-08-18 Nathan Sidwell <nathan@codesourcery.com> 2003-08-18 Nathan Sidwell <nathan@codesourcery.com>
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 * pt.c (instantiate_class_template): Push to class's scope before
tsubsting base. tsubsting base.
......
...@@ -4102,7 +4102,7 @@ extern tree finish_parenthesized_expr (tree); ...@@ -4102,7 +4102,7 @@ extern tree finish_parenthesized_expr (tree);
extern tree finish_non_static_data_member (tree, tree, tree); extern tree finish_non_static_data_member (tree, tree, tree);
extern tree begin_stmt_expr (void); extern tree begin_stmt_expr (void);
extern tree finish_stmt_expr_expr (tree); 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 perform_koenig_lookup (tree, tree);
extern tree finish_call_expr (tree, tree, bool); extern tree finish_call_expr (tree, tree, bool);
extern tree finish_increment_expr (tree, enum tree_code); extern tree finish_increment_expr (tree, enum tree_code);
......
...@@ -85,9 +85,7 @@ finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt) ...@@ -85,9 +85,7 @@ finish_init_stmts (bool is_global, tree stmt_expr, tree compound_stmt)
{ {
finish_compound_stmt (compound_stmt); finish_compound_stmt (compound_stmt);
stmt_expr = finish_stmt_expr (stmt_expr); stmt_expr = finish_stmt_expr (stmt_expr, true);
STMT_EXPR_NO_SCOPE (stmt_expr) = true;
TREE_USED (stmt_expr) = 1;
my_friendly_assert (!building_stmt_tree () == is_global, 20030726); 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) ...@@ -2478,7 +2476,7 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array)
base = cp_convert (ptype, decay_conversion (base)); base = cp_convert (ptype, decay_conversion (base));
/* The code we are generating looks like: /* The code we are generating looks like:
({
T* t1 = (T*) base; T* t1 = (T*) base;
T* rval = t1; T* rval = t1;
ptrdiff_t iterator = maxindex; ptrdiff_t iterator = maxindex;
...@@ -2490,7 +2488,8 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array) ...@@ -2490,7 +2488,8 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array)
} catch (...) { } catch (...) {
... destroy elements that were constructed ... ... destroy elements that were constructed ...
} }
return rval; rval;
})
We can omit the try and catch blocks if we know that the We can omit the try and catch blocks if we know that the
initialization will never throw an exception, or if the array 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) ...@@ -2662,18 +2661,22 @@ build_vec_init (tree base, tree maxindex, tree init, int from_array)
finish_compound_stmt (try_body); finish_compound_stmt (try_body);
finish_cleanup_try_block (try_block); finish_cleanup_try_block (try_block);
e = build_vec_delete_1 (rval, m, e = build_vec_delete_1 (rval, m, type, sfk_base_destructor,
type,
sfk_base_destructor,
/*use_global_delete=*/0); /*use_global_delete=*/0);
finish_cleanup (e, try_block); finish_cleanup (e, try_block);
} }
/* The value of the array initialization is the address of the /* The value of the array initialization is the array itself, RVAL
first element in the array. */ is a pointer to the first element. */
finish_expr_stmt (rval); finish_stmt_expr_expr (rval);
stmt_expr = finish_init_stmts (is_global, stmt_expr, compound_stmt); 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; current_stmt_tree ()->stmts_are_full_exprs_p = destroy_temps;
return stmt_expr; return stmt_expr;
} }
......
...@@ -2270,7 +2270,7 @@ cp_parser_primary_expression (cp_parser *parser, ...@@ -2270,7 +2270,7 @@ cp_parser_primary_expression (cp_parser *parser,
/* Parse the compound-statement. */ /* Parse the compound-statement. */
cp_parser_compound_statement (parser, true); cp_parser_compound_statement (parser, true);
/* Finish up. */ /* Finish up. */
expr = finish_stmt_expr (expr); expr = finish_stmt_expr (expr, false);
} }
else else
{ {
......
...@@ -7343,7 +7343,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl) ...@@ -7343,7 +7343,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
tsubst_expr (STMT_EXPR_STMT (t), args, tsubst_expr (STMT_EXPR_STMT (t), args,
complain | tf_stmt_expr_cmpd, in_decl); complain | tf_stmt_expr_cmpd, in_decl);
return finish_stmt_expr (stmt_expr); return finish_stmt_expr (stmt_expr, false);
} }
return t; return t;
......
...@@ -1405,7 +1405,7 @@ begin_stmt_expr (void) ...@@ -1405,7 +1405,7 @@ begin_stmt_expr (void)
last_expr_type = NULL_TREE; last_expr_type = NULL_TREE;
keep_next_level (1); keep_next_level (1);
return last_tree; return last_tree;
} }
...@@ -1469,13 +1469,12 @@ finish_stmt_expr_expr (tree expr) ...@@ -1469,13 +1469,12 @@ finish_stmt_expr_expr (tree expr)
return result; return result;
} }
/* Finish a statement-expression. RTL_EXPR should be the value /* Finish a statement-expression. EXPR should be the value returned
returned by the previous begin_stmt_expr; EXPR is the by the previous begin_stmt_expr. Returns an expression
statement-expression. Returns an expression representing the representing the statement-expression. */
statement-expression. */
tree tree
finish_stmt_expr (tree rtl_expr) finish_stmt_expr (tree rtl_expr, bool has_no_scope)
{ {
tree result; tree result;
tree result_stmt = last_expr_type; tree result_stmt = last_expr_type;
...@@ -1496,6 +1495,7 @@ finish_stmt_expr (tree rtl_expr) ...@@ -1496,6 +1495,7 @@ finish_stmt_expr (tree rtl_expr)
result = build_min (STMT_EXPR, type, last_tree); result = build_min (STMT_EXPR, type, last_tree);
TREE_SIDE_EFFECTS (result) = 1; TREE_SIDE_EFFECTS (result) = 1;
STMT_EXPR_NO_SCOPE (result) = has_no_scope;
last_expr_type = NULL_TREE; last_expr_type = NULL_TREE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment