cpplib.h (struct cpp_options): New member, warn_endif_labels.
authorPhil Edwards <pme@gcc.gnu.org>
Fri, 22 Mar 2002 21:59:04 +0000 (21:59 +0000)
committerPhil Edwards <pme@gcc.gnu.org>
Fri, 22 Mar 2002 21:59:04 +0000 (21:59 +0000)
2002-03-22  Phil Edwards  <pme@gcc.gnu.org>

* cpplib.h (struct cpp_options):  New member, warn_endif_labels.
* cppinit.c (cpp_create_reader):  On by default.
(cpp_handle_option):  Handle -W[no-]endif-labels.
(cpp_post_options):  Also enable if -pedantic.
* cpplib.c (do_else):  Use it.
(do_endif):  Likewise.
* doc/cppopts.texi:  Document new option.
* doc/invoke.texi:  Document new option.

From-SVN: r51190

gcc/ChangeLog
gcc/cppinit.c
gcc/cpplib.c
gcc/cpplib.h
gcc/doc/cppopts.texi
gcc/doc/invoke.texi

index c2e75f152270e7192ded3adc9e9009c416603a5c..09ea7641f6257f52036c87d40fa94f099e21b30c 100644 (file)
@@ -1,3 +1,14 @@
+2002-03-22  Phil Edwards  <pme@gcc.gnu.org>
+
+       * cpplib.h (struct cpp_options):  New member, warn_endif_labels.
+       * cppinit.c (cpp_create_reader):  On by default.
+       (cpp_handle_option):  Handle -W[no-]endif-labels.
+       (cpp_post_options):  Also enable if -pedantic.
+       * cpplib.c (do_else):  Use it.
+       (do_endif):  Likewise.
+       * doc/cppopts.texi:  Document new option.
+       * doc/invoke.texi:  Document new option.
+
 2002-03-22  Lars Brinkhoff  <lars@nocrew.org>
 
        * config/i386/i386.c, config/i386/i386.md: Change all occurences
index ae9416e8ade5f6bafdd618efb2b1d458024fde5a..d3d59ef4874eeb1eeb033f1a74223cc7275205dc 100644 (file)
@@ -491,6 +491,7 @@ cpp_create_reader (lang)
   CPP_OPTION (pfile, show_column) = 1;
   CPP_OPTION (pfile, tabstop) = 8;
   CPP_OPTION (pfile, operator_names) = 1;
+  CPP_OPTION (pfile, warn_endif_labels) = 1;
 #if DEFAULT_SIGNED_CHAR
   CPP_OPTION (pfile, signed_char) = 1;
 #else
@@ -1735,6 +1736,8 @@ cpp_handle_option (pfile, argc, argv, ignore)
            CPP_OPTION (pfile, warnings_are_errors) = 1;
          else if (!strcmp (argv[i], "-Wsystem-headers"))
            CPP_OPTION (pfile, warn_system_headers) = 1;
+         else if (!strcmp (argv[i], "-Wendif-labels"))
+           CPP_OPTION (pfile, warn_endif_labels) = 1;
          else if (!strcmp (argv[i], "-Wno-traditional"))
            CPP_OPTION (pfile, warn_traditional) = 0;
          else if (!strcmp (argv[i], "-Wno-trigraphs"))
@@ -1751,6 +1754,8 @@ cpp_handle_option (pfile, argc, argv, ignore)
            CPP_OPTION (pfile, warnings_are_errors) = 0;
          else if (!strcmp (argv[i], "-Wno-system-headers"))
            CPP_OPTION (pfile, warn_system_headers) = 0;
+         else if (!strcmp (argv[i], "-Wno-endif-labels"))
+           CPP_OPTION (pfile, warn_endif_labels) = 0;
          else if (! ignore)
            return i;
          break;
@@ -1832,6 +1837,10 @@ cpp_post_options (pfile)
        || CPP_OPTION (pfile, deps_file)
        || CPP_OPTION (pfile, deps_phony_targets)))
     cpp_fatal (pfile, "you must additionally specify either -M or -MM");
+
+  /* Some things should always be on in pedantic mode.  */
+  if (CPP_OPTION (pfile, pedantic) == 1)
+    CPP_OPTION (pfile, warn_endif_labels) = 1;
 }
 
 /* Set up dependency-file output.  On exit, if print_deps is non-zero
index d8e34330e281935b98a15dcea56e31cdab0bbbe0..9a6b077f24b40e1747986b87d4ed8dcd1ed537a2 100644 (file)
@@ -1375,7 +1375,7 @@ do_else (pfile)
       ifs->mi_cmacro = 0;
 
       /* Only check EOL if was not originally skipping.  */
-      if (!ifs->was_skipping)
+      if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels))
        check_eol (pfile);
     }
 }
@@ -1430,7 +1430,7 @@ do_endif (pfile)
   else
     {
       /* Only check EOL if was not originally skipping.  */
-      if (!ifs->was_skipping)
+      if (!ifs->was_skipping && CPP_OPTION (pfile, warn_endif_labels))
        check_eol (pfile);
 
       /* If potential control macro, we go back outside again.  */
index 191649ccfd651f95df1105629a3f3799aaff3432..783b25835b06764850a6483691d0eab1b3ad83e8 100644 (file)
@@ -308,6 +308,9 @@ struct cpp_options
      traditional C.  */
   unsigned char warn_traditional;
 
+  /* Nonzero means warn about text after an #endif (or #else).  */
+  unsigned char warn_endif_labels;
+
   /* Nonzero means turn warnings into errors.  */
   unsigned char warnings_are_errors;
 
index 463403e101a1a9071ae19f85a6eb4b1829c9d535..7ab651b7251d3309c52e1b81fa8540088456d90b 100644 (file)
@@ -110,6 +110,23 @@ Warn whenever an identifier which is not a macro is encountered in an
 @samp{#if} directive, outside of @samp{defined}.  Such identifiers are
 replaced with zero.
 
+@item -Wendif-labels
+@opindex Wendif-labels
+Warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
+This usually happens in code of the form
+
+@smallexample
+#if FOO
+@dots{}
+#else FOO
+@dots{}
+#endif FOO
+@end smallexample
+
+@noindent
+The second and third @code{FOO} should be in comments, but often are not
+in older programs.  This warning is on by default.
+
 @item -Werror
 @opindex Werror
 Make all warnings into hard errors.  Source code which triggers warnings
index 533fda1a4aaf74af534e8484c41f6e5630c2d009..7e6b714c9b5e0ee2da7318efbd2dcf9e78da0e50 100644 (file)
@@ -220,7 +220,7 @@ in the following sections.
 -Wimplicit  -Wimplicit-int  @gol
 -Wimplicit-function-declaration @gol
 -Werror-implicit-function-declaration @gol
--Wimport  -Winline @gol
+-Wimport  -Winline -Wno-endif-labels @gol
 -Wlarger-than-@var{len}  -Wlong-long @gol
 -Wmain  -Wmissing-braces  -Wmissing-declarations @gol
 -Wmissing-format-attribute  -Wmissing-noreturn @gol
@@ -2384,6 +2384,10 @@ conversion warnings, for the full set use @option{-Wconversion}.
 @opindex Wundef
 Warn if an undefined identifier is evaluated in an @samp{#if} directive.
 
+@item -Wendif-labels
+@opindex Wendif-labels
+Warn whenever an @samp{#else} or an @samp{#endif} are followed by text.
+
 @item -Wshadow
 @opindex Wshadow
 Warn whenever a local variable shadows another local variable, parameter or