aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2008-02-25 23:59:44 +0000
committerManuel López-Ibáñez <manu@gcc.gnu.org>2008-02-25 23:59:44 +0000
commit683d6ff954e871028b34e8bd5e9fdda491ec2cbf (patch)
tree64878ef154456615c954564cc936b478852e6c76 /gcc/c-common.c
parent369dcbd9d2f7d4577f689b46ee3028bc7949049c (diff)
downloadgcc-683d6ff954e871028b34e8bd5e9fdda491ec2cbf.zip
gcc-683d6ff954e871028b34e8bd5e9fdda491ec2cbf.tar.gz
gcc-683d6ff954e871028b34e8bd5e9fdda491ec2cbf.tar.bz2
c-common.c (match_case_to_enum_1): Add appropriate OPT_W* parameter to warning.
2008-02-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org> * c-common.c (match_case_to_enum_1): Add appropriate OPT_W* parameter to warning. (c_do_switch_warnings): Likewise. * c-typeck.c (warning_init): Add one more parameter following 'warning' function. (push_init_level): Update call to warning_init. (pop_init_level): Likewise. (add_pending_init): Likewise. (output_init_element: Likewise. cp/ * typeck.c (build_class_member_access_expr): Add appropriate OPT_W* parameter to warning. (build_reinterpret_cast_1): Likewise. * name-lookup.c (push_overloaded_decl): Likewise. testsuite/ * gcc.dg/Wswitch-enum-error.c: New. * gcc.dg/Wswitch-error.c: New. * gcc.dg/20011021-1.c: Use two directives to match two different messages. From-SVN: r132649
Diffstat (limited to 'gcc/c-common.c')
-rw-r--r--gcc/c-common.c25
1 files changed, 22 insertions, 3 deletions
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 59efb38..2b8790d 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -4329,10 +4329,12 @@ match_case_to_enum_1 (tree key, tree type, tree label)
TREE_INT_CST_HIGH (key), TREE_INT_CST_LOW (key));
if (TYPE_NAME (type) == 0)
- warning (0, "%Jcase value %qs not in enumerated type",
+ warning (warn_switch ? OPT_Wswitch : OPT_Wswitch_enum,
+ "%Jcase value %qs not in enumerated type",
CASE_LABEL (label), buf);
else
- warning (0, "%Jcase value %qs not in enumerated type %qT",
+ warning (warn_switch ? OPT_Wswitch : OPT_Wswitch_enum,
+ "%Jcase value %qs not in enumerated type %qT",
CASE_LABEL (label), buf, type);
}
@@ -4384,6 +4386,7 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
splay_tree_node default_node;
splay_tree_node node;
tree chain;
+ int saved_warn_switch;
if (!warn_switch && !warn_switch_enum && !warn_switch_default)
return;
@@ -4453,7 +4456,13 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
if (cond && tree_int_cst_compare (cond, value))
continue;
- warning (0, "%Henumeration value %qE not handled in switch",
+ /* If there is a default_node, the only relevant option is
+ Wswitch-enum. Otherwise, if both are enabled then we prefer
+ to warn using -Wswitch because -Wswitch is enabled by -Wall
+ while -Wswitch-enum is explicit. */
+ warning ((default_node || !warn_switch)
+ ? OPT_Wswitch_enum : OPT_Wswitch,
+ "%Henumeration value %qE not handled in switch",
&switch_location, TREE_PURPOSE (chain));
}
@@ -4465,7 +4474,17 @@ c_do_switch_warnings (splay_tree cases, location_t switch_location,
we should have marked both the lower bound and upper bound of
every disjoint case label, with CASE_LOW_SEEN and CASE_HIGH_SEEN
above. This scan also resets those fields. */
+
+ /* If there is a default_node, the only relevant option is
+ Wswitch-enum. Otherwise, if both are enabled then we prefer
+ to warn using -Wswitch because -Wswitch is enabled by -Wall
+ while -Wswitch-enum is explicit. */
+ saved_warn_switch = warn_switch;
+ if (default_node)
+ warn_switch = 0;
splay_tree_foreach (cases, match_case_to_enum, type);
+ warn_switch = saved_warn_switch;
+
}
/* Finish an expression taking the address of LABEL (an