aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-opts.c
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2009-04-15 15:51:26 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2009-04-15 15:51:26 +0000
commit6866c6e8ff0cbc1d57f9ae603b5af155def03484 (patch)
tree1f0d9f50c4eb35dde54f0cbacee826d856fe8113 /gcc/c-opts.c
parentf116fecf890dbc4aaacd256eb26459d7ece30e99 (diff)
downloadgcc-6866c6e8ff0cbc1d57f9ae603b5af155def03484.zip
gcc-6866c6e8ff0cbc1d57f9ae603b5af155def03484.tar.gz
gcc-6866c6e8ff0cbc1d57f9ae603b5af155def03484.tar.bz2
c.opt (Wenum-compare): Enable for C and Objc.
gcc/: * c.opt (Wenum-compare): Enable for C and Objc. Initialize to -1. * c-opts.c (c_common_handle_option): For C, set warn_enum_compare for -Wall and for -Wc++-compat. (c_common_post_options): For C++, set warn_enum_compare if not already set. * c-tree.h (struct c_expr): Add field original_type. (build_external_ref): Update declaration. * c-parser.c (c_parser_braced_init): Set original_type. (c_parser_initelt): Likewise. (c_parser_expr_no_commas): Likewise. (c_parser_conditional_expression): Likewise. (c_parser_cast_expression): Likewise. (c_parser_unary_expression): Likewise. Pull setting of original_code to top of function. (c_parser_sizeof_expression): Set original_type. (c_parser_alignof_expression): Likewise. (c_parser_postfix_expression): Likewise. Pull setting of original_code to top of function. (c_parser_postfix_expression_after_paren_type): Set original_type. (c_parser_postfix_expression_after_primary): Likewise. (c_parser_expression): Likewise. * c-typeck.c (build_external_ref): Add type parameter. Change all callers. (c_expr_sizeof_expr): Set original_type field. (parser_build_unary_op): Likewise. (parser_build_binary_op): Likewise. Optionally warn about comparisons of enums of different types. (digest_init): Set original_type field. (really_start_incremental_init): Likewise. (push_init_level, pop_init_level): Likewise. * doc/invoke.texi (Warning Options): -Wenum-compare now supported in C. gcc/testsuite/: * gcc.dg/Wenum-compare-1.c: New testcase. From-SVN: r146127
Diffstat (limited to 'gcc/c-opts.c')
-rw-r--r--gcc/c-opts.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/gcc/c-opts.c b/gcc/c-opts.c
index 54edf30..f619522 100644
--- a/gcc/c-opts.c
+++ b/gcc/c-opts.c
@@ -412,6 +412,12 @@ c_common_handle_option (size_t scode, const char *arg, int value)
can turn it off only if it's not explicit. */
if (warn_main == -1)
warn_main = (value ? 2 : 0);
+
+ /* In C, -Wall turns on -Wenum-compare, which we do here.
+ In C++ it is on by default, which is done in
+ c_common_post_options. */
+ if (warn_enum_compare == -1)
+ warn_enum_compare = value;
}
else
{
@@ -438,6 +444,13 @@ c_common_handle_option (size_t scode, const char *arg, int value)
cpp_opts->warn_comments = value;
break;
+ case OPT_Wc___compat:
+ /* Because -Wenum-compare is the default in C++, -Wc++-compat
+ implies -Wenum-compare. */
+ if (warn_enum_compare == -1 && value)
+ warn_enum_compare = value;
+ break;
+
case OPT_Wdeprecated:
cpp_opts->warn_deprecated = value;
break;
@@ -1099,6 +1112,12 @@ c_common_post_options (const char **pfilename)
if (warn_sign_conversion == -1)
warn_sign_conversion = (c_dialect_cxx ()) ? 0 : warn_conversion;
+ /* In C, -Wall and -Wc++-compat enable -Wenum-compare, which we do
+ in c_common_handle_option; if it has not yet been set, it is
+ disabled by default. In C++, it is enabled by default. */
+ if (warn_enum_compare == -1)
+ warn_enum_compare = c_dialect_cxx () ? 1 : 0;
+
/* -Wpacked-bitfield-compat is on by default for the C languages. The
warning is issued in stor-layout.c which is not part of the front-end so
we need to selectively turn it on here. */