diff --git a/gcc/ChangeLog b/gcc/ChangeLog index cc1f0c362f4..2137c70f1bc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +007-01-29 Manuel Lopez-Ibanez + + * c-decl.c (pop_scope): Replace warnings with call to + warn_for_unused_label. + * c-common.h (warn_for_unused_label): Declare. + * c-common.c (warn_for_unused_label): Define. + 2007-01-29 Manuel Lopez-Ibanez * tree-optimize.c (update_inlined_to_pointers): Delete unused diff --git a/gcc/c-common.c b/gcc/c-common.c index 4b1718cd817..1bd59ff5e22 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -6758,5 +6758,18 @@ warn_about_parentheses (enum tree_code code, enum tree_code code_left, "have their mathematical meaning"); } +/* If LABEL (a LABEL_DECL) has not been used, issue a warning. */ + +void +warn_for_unused_label (tree label) +{ + if (!TREE_USED (label)) + { + if (DECL_INITIAL (label)) + warning (OPT_Wunused_label, "label %q+D defined but not used", label); + else + warning (OPT_Wunused_label, "label %q+D declared but not defined", label); + } +} #include "gt-c-common.h" diff --git a/gcc/c-common.h b/gcc/c-common.h index 78b3497259d..5ad4582d240 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -868,6 +868,7 @@ extern tree builtin_type_for_size (int, bool); extern void warn_array_subscript_with_type_char (tree); extern void warn_about_parentheses (enum tree_code, enum tree_code, enum tree_code); +extern void warn_for_unused_label (tree label); /* In c-gimplify.c */ diff --git a/gcc/c-decl.c b/gcc/c-decl.c index f669a4729da..2f9ffc3b622 100644 --- a/gcc/c-decl.c +++ b/gcc/c-decl.c @@ -761,13 +761,9 @@ pop_scope (void) error ("label %q+D used but not defined", p); DECL_INITIAL (p) = error_mark_node; } - else if (!TREE_USED (p) && warn_unused_label) - { - if (DECL_INITIAL (p)) - warning (0, "label %q+D defined but not used", p); - else - warning (0, "label %q+D declared but not defined", p); - } + else + warn_for_unused_label (p); + /* Labels go in BLOCK_VARS. */ TREE_CHAIN (p) = BLOCK_VARS (block); BLOCK_VARS (block) = p; diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2d8264ea3ce..0746d6af30b 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2007-01-29 Manuel Lopez-Ibanez + + * decl.c (pop_label): Replace warning with call to + warn_for_unused_label. + 2007-01-28 Andrew Pinski PR C++/28988 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index dfd199b1a7e..cea649ad731 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -365,8 +365,8 @@ pop_label (tree label, tree old_value) /* Avoid crashing later. */ define_label (location, DECL_NAME (label)); } - else if (!TREE_USED (label)) - warning (OPT_Wunused_label, "label %q+D defined but not used", label); + else + warn_for_unused_label (label); } SET_IDENTIFIER_LABEL_VALUE (DECL_NAME (label), old_value);