summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorChristoph Mallon <christoph.mallon@gmx.de>2016-05-01 22:37:36 +0200
committerChristoph Mallon <christoph.mallon@gmx.de>2016-05-01 22:50:18 +0200
commit664fa9e8e06c8da05d9cd8069882fca1096eabff (patch)
tree7154d6abdf22eaa511f9838a4a23dcbff0920f47 /src
parent97aa744ddac052e22ff2caffd0d05d755f27f621 (diff)
Split '-Wparentheses' into 'Wparentheses-assignment', 'Wparentheses-comparison', 'Wparentheses-else', 'Wparentheses-logical' and 'Wparentheses-shift'.
Diffstat (limited to 'src')
-rw-r--r--src/driver/warning.c14
-rw-r--r--src/driver/warning.h6
-rw-r--r--src/parser/parser.c10
3 files changed, 23 insertions, 7 deletions
diff --git a/src/driver/warning.c b/src/driver/warning.c
index 5d9da6b..6a98b3a 100644
--- a/src/driver/warning.c
+++ b/src/driver/warning.c
@@ -43,6 +43,15 @@ void print_warning_opt_help(void)
#define SET(y) (void)(warning[y].state = (warning[y].state & ~off) | on)
+static void warn_parentheses(warn_state_t const on, warn_state_t const off)
+{
+ SET(WARN_PARENTHESES_ASSIGNMENT);
+ SET(WARN_PARENTHESES_COMPARISON);
+ SET(WARN_PARENTHESES_ELSE);
+ SET(WARN_PARENTHESES_LOGICAL);
+ SET(WARN_PARENTHESES_SHIFT);
+}
+
static void warn_unused(warn_state_t const on, warn_state_t const off)
{
SET(WARN_UNUSED_FUNCTION);
@@ -101,7 +110,6 @@ void set_warning_opt(const char *const opt)
SET(WARN_MISSING_VARIABLE_DECLARATIONS);
SET(WARN_NONNULL);
SET(WARN_OTHER);
- SET(WARN_PARENTHESES);
SET(WARN_POINTER_ARITH);
SET(WARN_REDUNDANT_DECLS);
SET(WARN_RETURN_TYPE);
@@ -112,6 +120,7 @@ void set_warning_opt(const char *const opt)
SET(WARN_UNINITIALIZED);
SET(WARN_UNKNOWN_PRAGMAS);
SET(WARN_UNREACHABLE_CODE);
+ warn_parentheses(on, off);
warn_unused(on, off);
}
OPTX("comments") {
@@ -133,6 +142,9 @@ extra:
SET(WARN_IMPLICIT_FUNCTION_DECLARATION);
SET(WARN_IMPLICIT_INT);
}
+ OPTX("parentheses") {
+ warn_parentheses(on, off);
+ }
OPTX("unused") {
warn_unused(on, off);
}
diff --git a/src/driver/warning.h b/src/driver/warning.h
index 4631441..9cf9383 100644
--- a/src/driver/warning.h
+++ b/src/driver/warning.h
@@ -59,7 +59,11 @@ void print_warning_opt_help(void);
M(WARN_OTHER, ON, "other", "Warnings not covered by any other option") \
M(WARN_PACKED, OFF, "packed", "Warn if a structure is given the packed attribute, but the packed attribute has no effect on the layout or size of the structure") \
M(WARN_PADDED, OFF, "padded", "Warn if padding is included in a structure, either to align an element of the structure or to align the whole structure") \
- M(WARN_PARENTHESES, OFF, "parentheses", "Warn if parentheses are omitted in certain contexts (assignment where truth value is expected, if-else-braces)") \
+ M(WARN_PARENTHESES_ASSIGNMENT, OFF, "parentheses-assignment", "Warn if parentheses are omitted around an assignment where truth value is expected") \
+ M(WARN_PARENTHESES_COMPARISON, OFF, "parentheses-comparison", "Warn if parentheses are omitted around a comparison as operand of another comparison") \
+ M(WARN_PARENTHESES_ELSE, OFF, "parentheses-else", "Warn if braces are omitted around an 'if-else' as consequence of an 'if'") \
+ M(WARN_PARENTHESES_LOGICAL, OFF, "parentheses-logical", "Warn if parentheses are omitted around an && as operand of an ||") \
+ M(WARN_PARENTHESES_SHIFT, OFF, "parentheses-shift", "Warn if parentheses are omitted around an additive operation as operand to a shift") \
M(WARN_PEDANTIC, OFF, "pedantic", "Warn for cases where the c standard isn't stricly followed (but where we can easily continue)") \
M(WARN_POINTER_ARITH, ON, "pointer-arith", "Warn about anything that depends on the 'size of' a function type or of 'void'") \
M(WARN_POINTER_SIGN, ON, "pointer-sign", "gcc silently allows casting int* to unsigned* if this is off") \
diff --git a/src/parser/parser.c b/src/parser/parser.c
index 0dc792a..a46d90e 100644
--- a/src/parser/parser.c
+++ b/src/parser/parser.c
@@ -7403,7 +7403,7 @@ static void warn_assignment_in_condition(const expression_t *const expr)
if (expr->base.parenthesized)
return;
position_t const *const pos = &expr->base.pos;
- warningf(WARN_PARENTHESES, pos,
+ warningf(WARN_PARENTHESES_ASSIGNMENT, pos,
"suggest parentheses around assignment used as truth value");
}
@@ -8080,7 +8080,7 @@ static void warn_addsub_in_shift(const expression_t *const expr)
}
position_t const *const pos = &expr->base.pos;
- warningf(WARN_PARENTHESES, pos,
+ warningf(WARN_PARENTHESES_SHIFT, pos,
"suggest parentheses around '%c' inside shift", op);
}
@@ -8313,7 +8313,7 @@ static void warn_comparison(position_t const *const pos,
case EXPR_BINARY_GREATEREQUAL:
case EXPR_BINARY_NOTEQUAL:
case EXPR_BINARY_EQUAL:
- warningf(WARN_PARENTHESES, pos,
+ warningf(WARN_PARENTHESES_COMPARISON, pos,
"comparisons like 'x <= y < z' do not have their mathematical meaning");
break;
default:
@@ -8581,7 +8581,7 @@ static void warn_logical_and_within_or(const expression_t *const expr)
if (expr->base.parenthesized)
return;
position_t const *const pos = &expr->base.pos;
- warningf(WARN_PARENTHESES, pos, "suggest parentheses around && within ||");
+ warningf(WARN_PARENTHESES_LOGICAL, pos, "suggest parentheses around && within ||");
}
/**
@@ -9651,7 +9651,7 @@ static statement_t *parse_if(void)
} else if (true_stmt->kind == STATEMENT_IF
&& true_stmt->ifs.false_statement != NULL) {
position_t const *const pos = &true_stmt->base.pos;
- warningf(WARN_PARENTHESES, pos,
+ warningf(WARN_PARENTHESES_ELSE, pos,
"suggest explicit braces to avoid ambiguous 'else'");
}