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
This commit is contained in:
Nathan Sidwell 2003-08-18 12:55:04 +00:00 committed by Nathan Sidwell
parent a2507277ed
commit 303b74068a
6 changed files with 34 additions and 20 deletions

View File

@ -1,5 +1,16 @@
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
tsubsting base.

View File

@ -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);

View File

@ -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;
}

View File

@ -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
{

View File

@ -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;

View File

@ -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;