aboutsummaryrefslogtreecommitdiff
path: root/gcc
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
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')
-rw-r--r--gcc/ChangeLog12
-rw-r--r--gcc/c-common.c25
-rw-r--r--gcc/c-typeck.c35
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/name-lookup.c2
-rw-r--r--gcc/cp/typeck.c13
-rw-r--r--gcc/testsuite/ChangeLog7
-rw-r--r--gcc/testsuite/gcc.dg/20011021-1.c8
-rw-r--r--gcc/testsuite/gcc.dg/Wswitch-enum-error.c63
-rw-r--r--gcc/testsuite/gcc.dg/Wswitch-error.c63
10 files changed, 206 insertions, 29 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 3607c3c..b8c7161 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,15 @@
+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
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
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 55b4b23..94d4eea8 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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);
}
/* 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 value)
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 value)
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 strict_string, tree type, tree field,
{
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;
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 388b2c0..2738490 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+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
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index 4a43cfa..74a25bd 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -1919,7 +1919,7 @@ push_overloaded_decl (tree decl, int flags, bool is_friend)
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))
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 81fbe77..bb8d71c 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -1934,9 +1934,11 @@ build_class_member_access_expr (tree object, tree member,
&& !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, tree expr, bool c_cast_p,
&& 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]. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 7dd0ff3..074e436 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,4 +1,11 @@
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
* gcc.dg/pr28322.c: New.
diff --git a/gcc/testsuite/gcc.dg/20011021-1.c b/gcc/testsuite/gcc.dg/20011021-1.c
index 821db47..dc998c8 100644
--- a/gcc/testsuite/gcc.dg/20011021-1.c
+++ b/gcc/testsuite/gcc.dg/20011021-1.c
@@ -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 "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 } */
diff --git a/gcc/testsuite/gcc.dg/Wswitch-enum-error.c b/gcc/testsuite/gcc.dg/Wswitch-enum-error.c
new file mode 100644
index 0000000..ae9a2c7
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wswitch-enum-error.c
@@ -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;
+}
diff --git a/gcc/testsuite/gcc.dg/Wswitch-error.c b/gcc/testsuite/gcc.dg/Wswitch-error.c
new file mode 100644
index 0000000..4aa0c2a1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wswitch-error.c
@@ -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;
+}