This is the mail archive of the gcc@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]

Re: warning: multi-line comment (why?)


Jan Dvorak wrote:
> I think it can be difficult. Referring to cpplex.c:
> 
> /* Skip a C++ line comment.  Handles escaped newlines.  Returns
>    non-zero if a multiline comment.  The following new line, if any,
>    is left in buffer->read_ahead.  */
...
> so you'll need lot of readahead and lot of work to get it working right.

No readahead -- if there is an escaped newline, that function already
reads and discards the following line.

See patch below.  How do I submit this?

-- Jamie

diff -u -w -r1.7827 ChangeLog
--- ChangeLog	2000/09/19 16:43:35	1.7827
+++ ChangeLog	2000/09/19 17:08:09
@@ -1,0 +1,6 @@
+2000-09-19  Jamie Lokier  <jamie.lokier@cern.ch>
+
+	* cpplex.c (skip_line_comment): Don't warn about multi-line
+	comments if the following line is another "//" comment.  Arg
+	changed from cpp_buffer* to cpp_reader*.
+
diff -u -w -r1.98 cpplex.c
--- cpplex.c	2000/09/18 18:43:04	1.98
+++ cpplex.c	2000/09/19 17:08:10
@@ -103,7 +103,7 @@
 static cppchar_t get_effective_char PARAMS ((cpp_buffer *));
 
 static int skip_block_comment PARAMS ((cpp_reader *));
-static int skip_line_comment PARAMS ((cpp_buffer *));
+static int skip_line_comment PARAMS ((cpp_reader *));
 static void adjust_column PARAMS ((cpp_reader *));
 static void skip_whitespace PARAMS ((cpp_reader *, cppchar_t));
 static cpp_hashnode *parse_identifier PARAMS ((cpp_reader *, cppchar_t));
@@ -816,14 +816,17 @@
   return c != '/' || prevc != '*';
 }
 
-/* Skip a C++ line comment.  Handles escaped newlines.  Returns
-   non-zero if a multiline comment.  The following new line, if any,
-   is left in buffer->read_ahead.  */
+/* Skip a C++ line comment.  Handles escaped newlines.  Returns non-zero
+   if a multiline comment that we should warn about.  That means there
+   is an escaped newline that is not followed by whitespace then "//".
+   The following new line, if any, is left in buffer->read_ahead.  */
 static int
-skip_line_comment (buffer)
-     cpp_buffer *buffer;
+skip_line_comment (pfile)
+     cpp_reader *pfile;
 {
+  cpp_buffer *buffer = pfile->buffer;
   unsigned int orig_lineno = buffer->lineno;
+  int multiline = 0;
   cppchar_t c;
 
   do
@@ -833,13 +836,36 @@
 	break;
 
       c = *buffer->cur++;
-      if (c == '?' || c == '\\')
+      if (c != '?' && c != '\\')
+	continue;
+
 	c = skip_escaped_newlines (buffer, c);
+      if (orig_lineno == buffer->lineno)
+	continue;
+      orig_lineno = buffer->lineno;
+
+      /* If c == EOF there'll be a warning about backslash-newline at
+	 end of the file.  No need for a multi-line warning as well. */
+      if (c == EOF)
+	continue;
+
+      /* If there is a newline and it is followed by whitespace then
+	 "//", don't warn about that as a multi-line comment. */
+      if (c == ' ' || c == '\t' || c == '\0')
+	{
+	  skip_whitespace (pfile, c);
+	  c = buffer->read_ahead;
+	}
+      if (c == '/' && buffer->cur < buffer->rlimit
+	  && (c = *buffer->cur++) == '/')
+	continue;
+
+      multiline = 1;
     }
   while (!is_vspace (c));
 
   buffer->read_ahead = c;	/* Leave any newline for caller.  */
-  return orig_lineno != buffer->lineno;
+  return multiline;
 }
 
 /* pfile->buffer->cur is one beyond the \t character.  Update
@@ -1342,7 +1368,7 @@
 	      comment_start = buffer->cur;
 
 	      /* Skip_line_comment updates buffer->read_ahead.  */
-	      if (skip_line_comment (buffer))
+	      if (skip_line_comment (pfile))
 		cpp_warning_with_line (pfile, result->line, result->col,
 				       "multi-line comment");
 

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