summaryrefslogtreecommitdiff
path: root/gcc/c-common.c
diff options
context:
space:
mode:
authormanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2008-02-25 23:59:44 +0000
committermanu <manu@138bc75d-0d04-0410-961f-82ee72b054a4>2008-02-25 23:59:44 +0000
commit6cbbbc890f416e20853af206510a93ecd5979c17 (patch)
tree64878ef154456615c954564cc936b478852e6c76 /gcc/c-common.c
parentddb48b8291f05bf65f23be0e77b2a23dbf4ce4a4 (diff)
downloadgcc-6cbbbc890f416e20853af206510a93ecd5979c17.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132649 138bc75d-0d04-0410-961f-82ee72b054a4
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 59efb38e796..2b8790d0729 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