This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] backslash-space-newline in comments


Hi!

IMHO we should not handle
// \<space><newline>
as multi-line comment, unlike outside of comment where this is most
definitely a bug, I guess it is much more common that white space in comment
is added after \ so that it would not result in a multi-line comment than
that anybody wants a multi-line comment and just has left unintentionally
space at the end.
E.g. http://www.cs.utwente.nl/~tcm is one of the things which now trigger the
multi-line comment warnings.
Ok to commit?

2001-04-11  Jakub Jelinek  <jakub@redhat.com>

	* cpplex.c (skip_escaped_newlines): backslash-whitespace-newline is
	different from backslash-newline in comments.
	* cpp.texi (-Wwhite-space): Remove.
	(-Wall): -Wall does not imply -Wwhite-space.

	* gcc.dg/cpp/backslash2.c: Test for backslash-whitespace-newline
	in C++ style comments.

--- gcc/testsuite/gcc.dg/cpp/backslash2.c.jj	Wed Dec  6 21:14:32 2000
+++ gcc/testsuite/gcc.dg/cpp/backslash2.c	Wed Apr 11 12:23:23 2001
@@ -1,6 +1,7 @@
-/* Copyright (C) 2000 Free Software Foundation, Inc.  */
+/* Copyright (C) 2000, 2001 Free Software Foundation, Inc.  */
 
 /* { dg-do preprocess } */
+/* { dg-options "-Wcomment" } */
 
 /* Test warnings for backslash-space-newline.
    Source: Neil Booth. 6 Dec 2000.  */
@@ -12,3 +13,10 @@ bar
 /* foo \   
    bar */
 /* { dg-bogus "separated by space" "" { target *-*-* } 12 } */
+
+// \ 
+//  \ 
+//   >--------->
+//  /
+// /
+/* { dg-bogus "multi-line comment" "" { target *-*-* } 17 } */
--- gcc/cpplex.c.jj	Wed Apr 11 12:36:27 2001
+++ gcc/cpplex.c	Wed Apr 11 13:11:43 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
@@ -230,14 +230,15 @@ skip_escaped_newlines (buffer, next)
 
 	  /* We have a backslash, and room for at least one more character.  */
 	  space = 0;
-	  do
-	    {
-	      next1 = *buffer->cur++;
-	      if (!is_nvspace (next1))
-		break;
-	      space = 1;
-	    }
-	  while (buffer->cur < buffer->rlimit);
+	  if (!buffer->pfile->state.lexing_comment)
+	    do
+	      {
+		next1 = *buffer->cur++;
+		if (!is_nvspace (next1))
+		  break;
+		space = 1;
+	      }
+	    while (buffer->cur < buffer->rlimit);
 
 	  if (!is_vspace (next1))
 	    {
@@ -245,7 +246,7 @@ skip_escaped_newlines (buffer, next)
 	      break;
 	    }
 
-	  if (space && !buffer->pfile->state.lexing_comment)
+	  if (space)
 	    cpp_warning (buffer->pfile,
 			 "backslash and newline separated by space");
 
--- gcc/cpp.texi.jj	Thu Mar 15 13:03:00 2001
+++ gcc/cpp.texi	Wed Apr 11 11:58:27 2001
@@ -3326,15 +3326,10 @@ only if @samp{-trigraphs} was also speci
 independently.  Warnings are not given for trigraphs within comments, as
 we feel this is obnoxious.
 
-@item -Wwhite-space
-@findex -Wwhite-space
-Warn about possible white space confusion, e.g. white space between a
-backslash and a newline.
-
 @item -Wall
 @findex -Wall
-Requests @samp{-Wcomment}, @samp{-Wtrigraphs}, and @samp{-Wwhite-space}
-(but not @samp{-Wtraditional} or @samp{-Wundef}).
+Requests @samp{-Wcomment} and @samp{-Wtrigraphs} (but not
+@samp{-Wtraditional} or @samp{-Wundef}).
 
 @item -Wtraditional
 @findex -Wtraditional

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]