summaryrefslogtreecommitdiff
path: root/gcc/cp/cvt.c
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-16 13:32:11 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-16 13:32:11 +0000
commit00fa9079fff8eb65ddbd0dab17e3ec4e6e3bd611 (patch)
tree0432e7399477735a910c874de61c6edf041c4dbe /gcc/cp/cvt.c
parent0785e435c4757f7248b96902a01350c7b2060c32 (diff)
downloadgcc-00fa9079fff8eb65ddbd0dab17e3ec4e6e3bd611.tar.gz
PR c++/11512
* stmt.c (expand_expr_stmt_value): Don't warn about any void typed expression. cp: PR c++/11512 * cvt.c (convert_to_void): Indicate which side of conditional has no effects, and rhs of comma operator. Test for no sideeffect expressions here and always build a convert expr. * init.c (expand_default_init): Convert the init to void. * typeck.c (build_x_compound_expr): Do not check for side effects here. (build_compound_expr): Do not convert lhs when building a template. testsuite: PR C++/11512 * g++.dg/template/warn1.C: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70505 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp/cvt.c')
-rw-r--r--gcc/cp/cvt.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c
index 2cdf3953534..0a8e4789b29 100644
--- a/gcc/cp/cvt.c
+++ b/gcc/cp/cvt.c
@@ -812,8 +812,12 @@ convert_to_void (tree expr, const char *implicit)
/* The two parts of a cond expr might be separate lvalues. */
tree op1 = TREE_OPERAND (expr,1);
tree op2 = TREE_OPERAND (expr,2);
- tree new_op1 = convert_to_void (op1, implicit);
- tree new_op2 = convert_to_void (op2, implicit);
+ tree new_op1 = convert_to_void
+ (op1, (implicit && !TREE_SIDE_EFFECTS (op2)
+ ? "second operand of conditional" : NULL));
+ tree new_op2 = convert_to_void
+ (op2, (implicit && !TREE_SIDE_EFFECTS (op1)
+ ? "third operand of conditional" : NULL));
expr = build (COND_EXPR, TREE_TYPE (new_op1),
TREE_OPERAND (expr, 0), new_op1, new_op2);
@@ -824,7 +828,8 @@ convert_to_void (tree expr, const char *implicit)
{
/* The second part of a compound expr contains the value. */
tree op1 = TREE_OPERAND (expr,1);
- tree new_op1 = convert_to_void (op1, implicit);
+ tree new_op1 = convert_to_void
+ (op1, implicit ? "right-hand operand of comma" : NULL);
if (new_op1 != op1)
{
@@ -901,13 +906,9 @@ convert_to_void (tree expr, const char *implicit)
if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr)))
{
- /* FIXME: This is where we should check for expressions with no
- effects. At the moment we do that in both build_x_component_expr
- and expand_expr_stmt -- inconsistently too. For the moment
- leave implicit void conversions unadorned so that expand_expr_stmt
- has a chance of detecting some of the cases. */
- if (!implicit)
- expr = build1 (CONVERT_EXPR, void_type_node, expr);
+ if (implicit && !TREE_SIDE_EFFECTS (expr) && warn_unused_value)
+ warning ("%s has no effect", implicit);
+ expr = build1 (CONVERT_EXPR, void_type_node, expr);
}
return expr;
}