aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-common.c
diff options
context:
space:
mode:
authorPaolo Carlini <paolo.carlini@oracle.com>2012-10-09 10:01:31 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2012-10-09 10:01:31 +0000
commit5d9de0d0a5b5e807c92f01712e8dad06e0dfae75 (patch)
tree4a7ba5472d1488e9d3da4e504e9a346b75459b6b /gcc/c-family/c-common.c
parent3b86789289cb2469341283dd2ee86d5c5b1bd30f (diff)
downloadgcc-5d9de0d0a5b5e807c92f01712e8dad06e0dfae75.zip
gcc-5d9de0d0a5b5e807c92f01712e8dad06e0dfae75.tar.gz
gcc-5d9de0d0a5b5e807c92f01712e8dad06e0dfae75.tar.bz2
re PR c++/54194 (misleading suggestion about arithmetic in operand of '|')
2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54194 * tree.h: Add EXPR_LOC_OR_LOC. c-family/ 2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54194 * c-common.c (warn_about_parentheses): Add location_t parameter; use EXPR_LOC_OR_LOC. * c-common.h: Update declaration. c/ 2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54194 * c-typeck.c (parser_build_binary_op): Update warn_about_parentheses call. /cp 2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54194 * typeck.c (build_x_binary_op): Update warn_about_parentheses call. * parser.c (cp_parser_binary_expression): Use SET_EXPR_LOCATION on current.lhs. /testsuite 2012-10-09 Paolo Carlini <paolo.carlini@oracle.com> PR c++/54194 * g++.dg/warn/Wparentheses-26.C: Adjust. * g++.dg/warn/Wparentheses-27.C: New. From-SVN: r192246
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r--gcc/c-family/c-common.c149
1 files changed, 96 insertions, 53 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index edd25aa..b918648 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -10527,7 +10527,7 @@ warn_array_subscript_with_type_char (tree index)
was enclosed in parentheses. */
void
-warn_about_parentheses (enum tree_code code,
+warn_about_parentheses (location_t loc, enum tree_code code,
enum tree_code code_left, tree arg_left,
enum tree_code code_right, tree arg_right)
{
@@ -10547,104 +10547,147 @@ warn_about_parentheses (enum tree_code code,
switch (code)
{
case LSHIFT_EXPR:
- if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
- warning (OPT_Wparentheses,
- "suggest parentheses around %<+%> inside %<<<%>");
- else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
- warning (OPT_Wparentheses,
- "suggest parentheses around %<-%> inside %<<<%>");
+ if (code_left == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<+%> inside %<<<%>");
+ else if (code_right == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "suggest parentheses around %<+%> inside %<<<%>");
+ else if (code_left == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<-%> inside %<<<%>");
+ else if (code_right == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "suggest parentheses around %<-%> inside %<<<%>");
return;
case RSHIFT_EXPR:
- if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
- warning (OPT_Wparentheses,
- "suggest parentheses around %<+%> inside %<>>%>");
- else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
- warning (OPT_Wparentheses,
- "suggest parentheses around %<-%> inside %<>>%>");
+ if (code_left == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<+%> inside %<>>%>");
+ else if (code_right == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "suggest parentheses around %<+%> inside %<>>%>");
+ else if (code_left == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<-%> inside %<>>%>");
+ else if (code_right == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "suggest parentheses around %<-%> inside %<>>%>");
return;
case TRUTH_ORIF_EXPR:
- if (code_left == TRUTH_ANDIF_EXPR || code_right == TRUTH_ANDIF_EXPR)
- warning (OPT_Wparentheses,
- "suggest parentheses around %<&&%> within %<||%>");
+ if (code_left == TRUTH_ANDIF_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<&&%> within %<||%>");
+ else if (code_right == TRUTH_ANDIF_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "suggest parentheses around %<&&%> within %<||%>");
return;
case BIT_IOR_EXPR:
if (code_left == BIT_AND_EXPR || code_left == BIT_XOR_EXPR
- || code_left == PLUS_EXPR || code_left == MINUS_EXPR
- || code_right == BIT_AND_EXPR || code_right == BIT_XOR_EXPR
- || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
- warning (OPT_Wparentheses,
+ || code_left == PLUS_EXPR || code_left == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around arithmetic in operand of %<|%>");
+ else if (code_right == BIT_AND_EXPR || code_right == BIT_XOR_EXPR
+ || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around arithmetic in operand of %<|%>");
/* Check cases like x|y==z */
- else if (TREE_CODE_CLASS (code_left) == tcc_comparison
- || TREE_CODE_CLASS (code_right) == tcc_comparison)
- warning (OPT_Wparentheses,
+ else if (TREE_CODE_CLASS (code_left) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around comparison in operand of %<|%>");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around comparison in operand of %<|%>");
/* Check cases like !x | y */
else if (code_left == TRUTH_NOT_EXPR
&& !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right, arg_right))
- warning (OPT_Wparentheses, "suggest parentheses around operand of "
- "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around operand of "
+ "%<!%> or change %<|%> to %<||%> or %<!%> to %<~%>");
return;
case BIT_XOR_EXPR:
if (code_left == BIT_AND_EXPR
- || code_left == PLUS_EXPR || code_left == MINUS_EXPR
- || code_right == BIT_AND_EXPR
- || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
- warning (OPT_Wparentheses,
+ || code_left == PLUS_EXPR || code_left == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around arithmetic in operand of %<^%>");
+ else if (code_right == BIT_AND_EXPR
+ || code_right == PLUS_EXPR || code_right == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around arithmetic in operand of %<^%>");
/* Check cases like x^y==z */
- else if (TREE_CODE_CLASS (code_left) == tcc_comparison
- || TREE_CODE_CLASS (code_right) == tcc_comparison)
- warning (OPT_Wparentheses,
+ else if (TREE_CODE_CLASS (code_left) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around comparison in operand of %<^%>");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around comparison in operand of %<^%>");
return;
case BIT_AND_EXPR:
- if (code_left == PLUS_EXPR || code_right == PLUS_EXPR)
- warning (OPT_Wparentheses,
+ if (code_left == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<+%> in operand of %<&%>");
+ else if (code_right == PLUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around %<+%> in operand of %<&%>");
- else if (code_left == MINUS_EXPR || code_right == MINUS_EXPR)
- warning (OPT_Wparentheses,
+ else if (code_left == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around %<-%> in operand of %<&%>");
+ else if (code_right == MINUS_EXPR)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around %<-%> in operand of %<&%>");
/* Check cases like x&y==z */
- else if (TREE_CODE_CLASS (code_left) == tcc_comparison
- || TREE_CODE_CLASS (code_right) == tcc_comparison)
- warning (OPT_Wparentheses,
+ else if (TREE_CODE_CLASS (code_left) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around comparison in operand of %<&%>");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around comparison in operand of %<&%>");
/* Check cases like !x & y */
else if (code_left == TRUTH_NOT_EXPR
&& !APPEARS_TO_BE_BOOLEAN_EXPR_P (code_right, arg_right))
- warning (OPT_Wparentheses, "suggest parentheses around operand of "
- "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around operand of "
+ "%<!%> or change %<&%> to %<&&%> or %<!%> to %<~%>");
return;
case EQ_EXPR:
- if (TREE_CODE_CLASS (code_left) == tcc_comparison
- || TREE_CODE_CLASS (code_right) == tcc_comparison)
- warning (OPT_Wparentheses,
+ if (TREE_CODE_CLASS (code_left) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around comparison in operand of %<==%>");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around comparison in operand of %<==%>");
return;
case NE_EXPR:
- if (TREE_CODE_CLASS (code_left) == tcc_comparison
- || TREE_CODE_CLASS (code_right) == tcc_comparison)
- warning (OPT_Wparentheses,
+ if (TREE_CODE_CLASS (code_left) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "suggest parentheses around comparison in operand of %<!=%>");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison)
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
"suggest parentheses around comparison in operand of %<!=%>");
return;
default:
- if (TREE_CODE_CLASS (code) == tcc_comparison
- && ((TREE_CODE_CLASS (code_left) == tcc_comparison
+ if (TREE_CODE_CLASS (code) == tcc_comparison)
+ {
+ if (TREE_CODE_CLASS (code_left) == tcc_comparison
&& code_left != NE_EXPR && code_left != EQ_EXPR
&& INTEGRAL_TYPE_P (TREE_TYPE (arg_left)))
- || (TREE_CODE_CLASS (code_right) == tcc_comparison
+ warning_at (EXPR_LOC_OR_LOC (arg_left, loc), OPT_Wparentheses,
+ "comparisons like %<X<=Y<=Z%> do not "
+ "have their mathematical meaning");
+ else if (TREE_CODE_CLASS (code_right) == tcc_comparison
&& code_right != NE_EXPR && code_right != EQ_EXPR
- && INTEGRAL_TYPE_P (TREE_TYPE (arg_right)))))
- warning (OPT_Wparentheses, "comparisons like %<X<=Y<=Z%> do not "
- "have their mathematical meaning");
+ && INTEGRAL_TYPE_P (TREE_TYPE (arg_right)))
+ warning_at (EXPR_LOC_OR_LOC (arg_right, loc), OPT_Wparentheses,
+ "comparisons like %<X<=Y<=Z%> do not "
+ "have their mathematical meaning");
+ }
return;
}
#undef NOT_A_BOOLEAN_EXPR_P