* Add appropriate OPT_W* to warnings.
@ 2008-02-25 17:08 Manuel López-Ibáñez
2008-02-25 20:05 ` Gabriel Dos Reis
0 siblings, 1 reply; 2+ messages in thread
From: Manuel López-Ibáñez @ 2008-02-25 17:08 UTC (permalink / raw)
To: GCC Patches
[-- Attachment #1: Type: text/plain, Size: 1057 bytes --]
This patch adds the appropriate OPT_W option to several warnings. I
only went for the clear cases that won't change the current behaviour
with respect to -Woption and -Wno-option but will enable
-Werror=option and -Wno-error=option.
Bootstrapped and regression tested on x86_64-unknown-linux-gnu.
OK for trunk?
2008-02-25 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/20011021-1.c: Use two directives to match two different
messages.
* gcc.dg/Wswitch-enum-error.c: New.
* gcc.dg/Wswitch-error.c: New.
[-- Attachment #2: fix-warning0.diff --]
[-- Type: text/plain, Size: 13421 bytes --]
Index: gcc/testsuite/gcc.dg/Wswitch-enum-error.c
===================================================================
--- gcc/testsuite/gcc.dg/Wswitch-enum-error.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wswitch-enum-error.c (revision 0)
@@ -0,0 +1,63 @@
+
+/* { dg-do compile } */
+/* { dg-options "-Werror=switch-enum -Wswitch" } */
+
+enum e { e1, e2 };
+
+int
+foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
+ enum e em, enum e en, enum e eo, enum e ep)
+{
+ switch (i)
+ {
+ case 1: return 1;
+ case 2: return 2;
+ }
+ switch (j)
+ {
+ case 3: return 4;
+ case 4: return 3;
+ default: break;
+ }
+ switch (ei) /* { dg-warning "enumeration value 'e1' not handled in switch" "enum e1" } */
+ { /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" { target *-*-* } 22 } */
+ }
+ switch (ej) /* { dg-error "enumeration value 'e1' not handled in switch" "enum e1" } */
+ { /* { dg-error "enumeration value 'e2' not handled in switch" "enum e2" { target *-*-* } 25 } */
+ default: break;
+ }
+ switch (ek) /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" } */
+ {
+ case e1: return 1;
+ }
+ switch (el) /* { dg-error "enumeration value 'e2' not handled in switch" "enum e2" } */
+ {
+ case e1: return 1;
+ default: break;
+ }
+ switch (em)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ }
+ switch (en)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ default: break;
+ }
+ switch (eo)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ case 3: return 3; /* { dg-warning "case value '3' not in enumerated type 'enum e'" "excess 3" } */
+ }
+ switch (ep)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ case 3: return 3; /* { dg-error "case value '3' not in enumerated type 'enum e'" "excess 3" } */
+ default: break;
+ }
+ return 0;
+}
Index: gcc/testsuite/gcc.dg/Wswitch-error.c
===================================================================
--- gcc/testsuite/gcc.dg/Wswitch-error.c (revision 0)
+++ gcc/testsuite/gcc.dg/Wswitch-error.c (revision 0)
@@ -0,0 +1,63 @@
+
+/* { dg-do compile } */
+/* { dg-options "-Werror=switch -Wswitch-enum" } */
+
+enum e { e1, e2 };
+
+int
+foo (int i, int j, enum e ei, enum e ej, enum e ek, enum e el,
+ enum e em, enum e en, enum e eo, enum e ep)
+{
+ switch (i)
+ {
+ case 1: return 1;
+ case 2: return 2;
+ }
+ switch (j)
+ {
+ case 3: return 4;
+ case 4: return 3;
+ default: break;
+ }
+ switch (ei) /* { dg-error "enumeration value 'e1' not handled in switch" "enum e1" } */
+ { /* { dg-error "enumeration value 'e2' not handled in switch" "enum e2" { target *-*-* } 22 } */
+ }
+ switch (ej) /* { dg-warning "enumeration value 'e1' not handled in switch" "enum e1" } */
+ { /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" { target *-*-* } 25 } */
+ default: break;
+ }
+ switch (ek) /* { dg-error "enumeration value 'e2' not handled in switch" "enum e2" } */
+ {
+ case e1: return 1;
+ }
+ switch (el) /* { dg-warning "enumeration value 'e2' not handled in switch" "enum e2" } */
+ {
+ case e1: return 1;
+ default: break;
+ }
+ switch (em)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ }
+ switch (en)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ default: break;
+ }
+ switch (eo)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ case 3: return 3; /* { dg-error "case value '3' not in enumerated type 'enum e'" "excess 3" } */
+ }
+ switch (ep)
+ {
+ case e1: return 1;
+ case e2: return 2;
+ case 3: return 3; /* { dg-warning "case value '3' not in enumerated type 'enum e'" "excess 3" } */
+ default: break;
+ }
+ return 0;
+}
Index: gcc/testsuite/gcc.dg/20011021-1.c
===================================================================
--- gcc/testsuite/gcc.dg/20011021-1.c (revision 132629)
+++ gcc/testsuite/gcc.dg/20011021-1.c (working copy)
@@ -27,7 +27,8 @@ struct multilevel
char *f;
};
-struct t T0 = { 1 }; /* { dg-warning "(missing|near) init" } */
+struct t T0 = { 1 }; /* { dg-warning "missing init" } */
+/* { dg-warning "near init" "near init" { target *-*-* } 30 } */
struct t T1 = { .a = 1 }; /* { dg-bogus "(missing|near) init" } */
union u U0 = { 1 }; /* { dg-warning "initialization of union" } */
@@ -36,8 +37,9 @@ union u U1 = { .i = 1 }; /* { dg-bogus "
struct multilevel M =
{
12,
- { .b = 3 }, /* { dg-bogus "(missing|near) init" } */
+ { .b = 3 }, /* { dg-bogus "missing init" } */
{ 4 }, /* { dg-warning "initialization of union" } */
{ .n = 9 }, /* { dg-bogus "initialization of union" } */
/* "string here" */
-}; /* { dg-warning "(missing|near) init" } */
+}; /* { dg-warning "missing init" } */
+/* { dg-warning "near init" "near init" { target *-*-* } 44 } */
Index: gcc/cp/typeck.c
===================================================================
--- gcc/cp/typeck.c (revision 132629)
+++ gcc/cp/typeck.c (working copy)
@@ -1934,9 +1934,11 @@ build_class_member_access_expr (tree obj
&& !DECL_FIELD_IS_BASE (member)
&& !skip_evaluation)
{
- warning (0, "invalid access to non-static data member %qD of NULL object",
- member);
- warning (0, "(perhaps the %<offsetof%> macro was used incorrectly)");
+ warning (OPT_Winvalid_offsetof,
+ "invalid access to non-static data member %qD "
+ " of NULL object", member);
+ warning (OPT_Winvalid_offsetof,
+ "(perhaps the %<offsetof%> macro was used incorrectly)");
}
/* If MEMBER is from an anonymous aggregate, we have converted
@@ -5337,9 +5339,8 @@ build_reinterpret_cast_1 (tree type, tre
&& COMPLETE_TYPE_P (TREE_TYPE (type))
&& COMPLETE_TYPE_P (TREE_TYPE (intype))
&& TYPE_ALIGN (TREE_TYPE (type)) > TYPE_ALIGN (TREE_TYPE (intype)))
- warning (0, "cast from %qT to %qT increases required alignment of "
- "target type",
- intype, type);
+ warning (OPT_Wcast_align, "cast from %qT to %qT "
+ "increases required alignment of target type", intype, type);
/* We need to strip nops here, because the front end likes to
create (int *)&a for array-to-pointer decay, instead of &a[0]. */
Index: gcc/cp/name-lookup.c
===================================================================
--- gcc/cp/name-lookup.c (revision 132629)
+++ gcc/cp/name-lookup.c (working copy)
@@ -1919,7 +1919,7 @@ push_overloaded_decl (tree decl, int fla
if (IS_AGGR_TYPE (t) && warn_shadow
&& (! DECL_IN_SYSTEM_HEADER (decl)
|| ! DECL_IN_SYSTEM_HEADER (old)))
- warning (0, "%q#D hides constructor for %q#T", decl, t);
+ warning (OPT_Wshadow, "%q#D hides constructor for %q#T", decl, t);
old = NULL_TREE;
}
else if (is_overloaded_fn (old))
Index: gcc/c-typeck.c
===================================================================
--- gcc/c-typeck.c (revision 132629)
+++ gcc/c-typeck.c (working copy)
@@ -91,7 +91,7 @@ static void push_string (const char *);
static void push_member_name (tree);
static int spelling_length (void);
static char *print_spelling (char *);
-static void warning_init (const char *);
+static void warning_init (int, const char *);
static tree digest_init (tree, tree, bool, int);
static void output_init_element (tree, bool, tree, tree, int);
static void output_pending_init_elements (int);
@@ -4636,19 +4636,21 @@ pedwarn_init (const char *msgid)
pedwarn ("(near initialization for %qs)", ofwhat);
}
-/* Issue a warning for a bad initializer component.
- MSGID identifies the message.
- The component name is taken from the spelling stack. */
+/* Issue a warning for a bad initializer component.
+
+ OPT is the OPT_W* value corresponding to the warning option that
+ controls this warning. MSGID identifies the message. The
+ component name is taken from the spelling stack. */
static void
-warning_init (const char *msgid)
+warning_init (int opt, const char *msgid)
{
char *ofwhat;
- warning (0, "%s", _(msgid));
+ warning (opt, "%s", _(msgid));
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat)
- warning (0, "(near initialization for %qs)", ofwhat);
+ warning (opt, "(near initialization for %qs)", ofwhat);
}
\f
/* If TYPE is an array type and EXPR is a parenthesized string
@@ -5415,7 +5417,7 @@ push_init_level (int implicit)
if (implicit == 1 && warn_missing_braces && !missing_braces_mentioned)
{
missing_braces_mentioned = 1;
- warning_init ("missing braces around initializer");
+ warning_init (OPT_Wmissing_braces, "missing braces around initializer");
}
if (TREE_CODE (constructor_type) == RECORD_TYPE
@@ -5476,7 +5478,7 @@ push_init_level (int implicit)
else
{
if (constructor_type != error_mark_node)
- warning_init ("braces around scalar initializer");
+ warning_init (0, "braces around scalar initializer");
constructor_fields = constructor_type;
constructor_unfilled_fields = constructor_type;
}
@@ -5562,7 +5564,8 @@ pop_init_level (int implicit)
if (constructor_unfilled_fields && !constructor_designated)
{
push_member_name (constructor_unfilled_fields);
- warning_init ("missing initializer");
+ warning_init (OPT_Wmissing_field_initializers,
+ "missing initializer");
RESTORE_SPELLING_DEPTH (constructor_depth);
}
}
@@ -5846,9 +5849,9 @@ add_pending_init (tree purpose, tree val
else
{
if (TREE_SIDE_EFFECTS (p->value))
- warning_init ("initialized field with side-effects overwritten");
+ warning_init (0, "initialized field with side-effects overwritten");
else if (warn_override_init)
- warning_init ("initialized field overwritten");
+ warning_init (OPT_Woverride_init, "initialized field overwritten");
p->value = value;
return;
}
@@ -5869,9 +5872,9 @@ add_pending_init (tree purpose, tree val
else
{
if (TREE_SIDE_EFFECTS (p->value))
- warning_init ("initialized field with side-effects overwritten");
+ warning_init (0, "initialized field with side-effects overwritten");
else if (warn_override_init)
- warning_init ("initialized field overwritten");
+ warning_init (OPT_Woverride_init, "initialized field overwritten");
p->value = value;
return;
}
@@ -6343,9 +6346,9 @@ output_init_element (tree value, bool st
{
if (TREE_SIDE_EFFECTS (VEC_last (constructor_elt,
constructor_elements)->value))
- warning_init ("initialized field with side-effects overwritten");
+ warning_init (0, "initialized field with side-effects overwritten");
else if (warn_override_init)
- warning_init ("initialized field overwritten");
+ warning_init (OPT_Woverride_init, "initialized field overwritten");
/* We can have just one union field set. */
constructor_elements = 0;
Index: gcc/c-common.c
===================================================================
--- gcc/c-common.c (revision 132629)
+++ gcc/c-common.c (working copy)
@@ -4329,10 +4329,12 @@ match_case_to_enum_1 (tree key, tree typ
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,
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,
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,
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Add appropriate OPT_W* to warnings.
2008-02-25 17:08 Add appropriate OPT_W* to warnings Manuel López-Ibáñez
@ 2008-02-25 20:05 ` Gabriel Dos Reis
0 siblings, 0 replies; 2+ messages in thread
From: Gabriel Dos Reis @ 2008-02-25 20:05 UTC (permalink / raw)
To: Manuel López-Ibáñez; +Cc: GCC Patches
On Mon, Feb 25, 2008 at 11:04 AM, Manuel López-Ibáñez
<lopezibanez@gmail.com> wrote:
> This patch adds the appropriate OPT_W option to several warnings. I
> only went for the clear cases that won't change the current behaviour
> with respect to -Woption and -Wno-option but will enable
> -Werror=option and -Wno-error=option.
>
> Bootstrapped and regression tested on x86_64-unknown-linux-gnu.
>
> OK for trunk?
Yes.
-- Gaby
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2008-02-25 20:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-25 17:08 Add appropriate OPT_W* to warnings Manuel López-Ibáñez
2008-02-25 20:05 ` Gabriel Dos Reis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).