[PATCH] Fix cpp to match cpp.texi in respect to warnings
Jakub Jelinek
jakub@redhat.com
Tue Apr 10 14:01:00 GMT 2001
Hi!
cpp.texi sais about -Wcomment that it enables warning whenever
backslash-newline appears in a // comment, but in reality this warning is
issued unconditionally. Likewise, cpp.texi speaks about -Wwhite-space, but
the warning is unconditional too.
This patch changes cpp0 to match its documentation.
Bootstrapped on i386-redhat-linux, no regressions.
Ok to commit?
2001-04-10 Jakub Jelinek <jakub@redhat.com>
* cpplex.c (skip_escaped_lines): Only warn if -Wwhite-space.
(_cpp_lex_token): Only warn if -Wcomment.
(cpp_handle_option): Handle -Wwhite-space.
* cpplib.h (struct cpp_options): Add warn_white_space.
* gcc.dg/cpp/backslash.c: Compile with -Wwhite-space.
* gcc.dg/cpp/backslash2.c: Likewise.
--- gcc/cpplex.c.jj Fri Mar 30 11:44:42 2001
+++ gcc/cpplex.c Tue Apr 10 18:33:34 2001
@@ -1,5 +1,5 @@
/* CPP Library - lexical analysis.
- Copyright (C) 2000 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001 Free Software Foundation, Inc.
Contributed by Per Bothner, 1994-95.
Based on CCCP program by Paul Rubin, June 1986
Adapted to ANSI C, Richard Stallman, Jan 1987
@@ -245,7 +245,8 @@ skip_escaped_newlines (buffer, next)
break;
}
- if (space && !buffer->pfile->state.lexing_comment)
+ if (CPP_OPTION (buffer->pfile, warn_white_space)
+ && space && !buffer->pfile->state.lexing_comment)
cpp_warning (buffer->pfile,
"backslash and newline separated by space");
@@ -1017,7 +1018,7 @@ _cpp_lex_token (pfile, result)
}
/* Skip_line_comment updates buffer->read_ahead. */
- if (skip_line_comment (pfile))
+ if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments))
cpp_warning_with_line (pfile, pfile->lexer_pos.line,
pfile->lexer_pos.col,
"multi-line comment");
--- gcc/cppinit.c.jj Tue Apr 10 17:42:17 2001
+++ gcc/cppinit.c Tue Apr 10 18:27:47 2001
@@ -1621,6 +1621,7 @@ cpp_handle_option (pfile, argc, argv)
{
CPP_OPTION (pfile, warn_trigraphs) = 1;
CPP_OPTION (pfile, warn_comments) = 1;
+ CPP_OPTION (pfile, warn_white_space) = 1;
}
else if (!strcmp (argv[i], "-Wtraditional"))
CPP_OPTION (pfile, warn_traditional) = 1;
@@ -1632,6 +1633,8 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, warn_comments) = 1;
else if (!strcmp (argv[i], "-Wundef"))
CPP_OPTION (pfile, warn_undef) = 1;
+ else if (!strcmp (argv[i], "-Wwhite-space"))
+ CPP_OPTION (pfile, warn_white_space) = 1;
else if (!strcmp (argv[i], "-Wimport"))
CPP_OPTION (pfile, warn_import) = 1;
else if (!strcmp (argv[i], "-Werror"))
@@ -1648,6 +1651,8 @@ cpp_handle_option (pfile, argc, argv)
CPP_OPTION (pfile, warn_comments) = 0;
else if (!strcmp (argv[i], "-Wno-undef"))
CPP_OPTION (pfile, warn_undef) = 0;
+ else if (!strcmp (argv[i], "-Wno-white-space"))
+ CPP_OPTION (pfile, warn_white_space) = 0;
else if (!strcmp (argv[i], "-Wno-import"))
CPP_OPTION (pfile, warn_import) = 0;
else if (!strcmp (argv[i], "-Wno-error"))
--- gcc/cpplib.h.jj Mon Mar 12 11:45:01 2001
+++ gcc/cpplib.h Tue Apr 10 18:29:08 2001
@@ -316,6 +316,10 @@ struct cpp_options
/* Nonzero means warn if slash-star appears in a comment. */
unsigned char warn_comments;
+ /* Nonzero means warn if white-space appears inappropriately (e.g.
+ between backslash and newline. */
+ unsigned char warn_white_space;
+
/* Nonzero means warn if there are any trigraphs. */
unsigned char warn_trigraphs;
--- gcc/testsuite/gcc.dg/cpp/backslash.c.jj Tue Sep 12 05:42:30 2000
+++ gcc/testsuite/gcc.dg/cpp/backslash.c Tue Apr 10 19:50:16 2001
@@ -1,4 +1,5 @@
/* Test backslash newline with and without trailing spaces. */
+/* { dg-options "-Wwhite-space" } */
#define alpha(a, b, c) \
a, \
@@ -11,9 +12,9 @@
b, \
c
-/* { dg-warning "separated by space" "space" { target *-*-* } 9 } */
-/* { dg-warning "separated by space" "tab" { target *-*-* } 10 } */
-/* { dg-warning "separated by space" "space and tab" { target *-*-* } 11 } */
+/* { dg-warning "separated by space" "space" { target *-*-* } 10 } */
+/* { dg-warning "separated by space" "tab" { target *-*-* } 11 } */
+/* { dg-warning "separated by space" "space and tab" { target *-*-* } 12 } */
int x[] = {
alpha(1, 2, 3),
--- gcc/testsuite/gcc.dg/cpp/backslash2.c.jj Wed Dec 6 21:14:32 2000
+++ gcc/testsuite/gcc.dg/cpp/backslash2.c Tue Apr 10 19:50:54 2001
@@ -1,14 +1,15 @@
/* Copyright (C) 2000 Free Software Foundation, Inc. */
/* { dg-do preprocess } */
+/* { dg-options "-Wwhite-space" } */
/* Test warnings for backslash-space-newline.
Source: Neil Booth. 6 Dec 2000. */
foo \
bar
-/* { dg-warning "separated by space" "" { target *-*-* } 8 } */
+/* { dg-warning "separated by space" "" { target *-*-* } 9 } */
/* foo \
bar */
-/* { dg-bogus "separated by space" "" { target *-*-* } 12 } */
+/* { dg-bogus "separated by space" "" { target *-*-* } 13 } */
Jakub
More information about the Gcc-patches
mailing list