diff options
author | Richard Kenner <kenner@gcc.gnu.org> | 1995-03-30 18:21:34 -0500 |
---|---|---|
committer | Richard Kenner <kenner@gcc.gnu.org> | 1995-03-30 18:21:34 -0500 |
commit | 0e7c47fabe920d561372f1fbf4773f499563db5f (patch) | |
tree | c0c4e5d0eea22a70753b3b2b09f7e9dea653746e /gcc | |
parent | 515a7242ff3435dc83e8a5ea31660156f7fdc33f (diff) | |
download | gcc-0e7c47fabe920d561372f1fbf4773f499563db5f.zip gcc-0e7c47fabe920d561372f1fbf4773f499563db5f.tar.gz gcc-0e7c47fabe920d561372f1fbf4773f499563db5f.tar.bz2 |
(internal_build_compound_expr): Warn if LHS of comma expression has no side effects...
(internal_build_compound_expr): Warn if LHS of comma expression has no
side effects, or computes value which is not used.
From-SVN: r9264
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-typeck.c | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index d9d58af..e4cfd45 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -3478,10 +3478,28 @@ internal_build_compound_expr (list, first_p) rest = internal_build_compound_expr (TREE_CHAIN (list), FALSE); - /* When pedantic, a compound expression can be neither an lvalue - nor an integer constant expression. */ - if (! TREE_SIDE_EFFECTS (TREE_VALUE (list)) && ! pedantic) - return rest; + if (! TREE_SIDE_EFFECTS (TREE_VALUE (list))) + { + /* The left-hand operand of a comma expression is like an expression + statement: with -W or -Wunused, we should warn if it doesn't have + any side-effects, unless it was explicitly cast to (void). */ + if ((extra_warnings || warn_unused) + && ! (TREE_CODE (TREE_VALUE (list)) == CONVERT_EXPR + && TREE_TYPE (TREE_VALUE (list)) == void_type_node)) + warning ("left-hand operand of comma expression has no effect"); + + /* When pedantic, a compound expression can be neither an lvalue + nor an integer constant expression. */ + if (! pedantic) + return rest; + } + + /* With -Wunused, we should also warn if the left-hand operand does have + side-effects, but computes a value which is not used. For example, in + `foo() + bar(), baz()' the result of the `+' operator is not used, + so we should issue a warning. */ + else if (warn_unused) + warn_if_unused_value (TREE_VALUE (list)); return build (COMPOUND_EXPR, TREE_TYPE (rest), TREE_VALUE (list), rest); } |