+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.
+
2008-02-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 28322
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);
}
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;
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));
}
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
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);
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
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
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;
}
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);
}
}
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;
}
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;
}
{
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;
+2008-02-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ * 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.
+
2008-02-25 Paolo Carlini <pcarlini@suse.de>
PR c++/35333
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))
&& !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
&& 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]. */
+2008-02-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+
+ * 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.
+
2008-02-26 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
PR 28322
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" } */
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 } */
--- /dev/null
+
+/* { 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;
+}
--- /dev/null
+
+/* { 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;
+}