public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jamie Lokier <egcs@tantalophile.demon.co.uk>
To: Neil Booth <NeilB@earthling.net>
Cc: Jan Dvorak <johnydog@go.cz>,
	Craig Rodrigues <rodrigc@mediaone.net>,
	gcc@gcc.gnu.org, gcc-patches@gcc.gnu.org
Subject: Re: warning: multi-line comment (why?)
Date: Mon, 25 Sep 2000 12:52:00 -0000	[thread overview]
Message-ID: <20000925215143.A16833@pcep-jamie.cern.ch> (raw)
In-Reply-To: <20000920172728.A17616@daikokuya.demon.co.uk>

Neil Booth wrote:
> // this \
> /\
> / is all one comment.
> 
> I know it's pedantic, but it's valid and we should continue to get it
> right.  I think your loop will terminate the comment at the end of the
> 2nd line.  A call to get_effective_char will handle that (instead of
> buffer->cur++).
> 
> If you do this, would you provide a testcase for the bug above, and
> that ensures the warning about multiline comments in not emitted in
> the case you're talking about?  Don't bother about null character
> testcases; in my experience they really confuse CVS.

Neal, you're right my loop was broken with /\<newline>/.  Please find
attached one patch and one test case.  I don't have Dejagnu installed
but I've formatted the test case that way so you can give it a try.

If you like the patch I'll need to send in the copyright assignment
form.

enjoy,
-- Jamie

2000-09-25  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.

Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.101
diff -u -w -r1.101 cpplex.c
--- cpplex.c	2000/09/24 10:42:09	1.101
+++ cpplex.c	2000/09/25 19:39:52
@@ -796,15 +796,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 (pfile)
      cpp_reader *pfile;
 {
   cpp_buffer *buffer = pfile->buffer;
   unsigned int orig_lineno = buffer->lineno;
+  int multiline = 0;
   cppchar_t c;
 
   pfile->state.lexing_comment = 1;
@@ -815,14 +817,43 @@
 	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;
+
+      /* Skip only ' ' and \t, on the subsequent comment line. */
+      while (is_hspace (c))
+	{
+	  if (c == '\t')
+	    adjust_column (pfile);
+	  c = EOF;
+	  if (buffer->cur == buffer->rlimit)
+	    break;
+	  c = *buffer->cur++;
+	}
+
+      /* If the next token isn't literally "//", warn about a multi-line
+	 comment.  Take care with "/\<newline>/": do warn about
+	 multi-line in this case, and do continue the comment. */
+      if (c == '/' && buffer->cur < buffer->rlimit && *buffer->cur == '/')
+	buffer->cur++;
+      else
+	multiline = 1;
     }
   while (!is_vspace (c));
 
   pfile->state.lexing_comment = 0;
   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


---------------------
testsuite/gcc.dg/cpp/multiline.c (how do you make a cvs-style diff
against a file which isn't in the repository?)

/* { dg-do compile } */

/* Warn about multi-line //-style comments, but not when the subsequent
   lines are also //-style comments.  Contributed by Jamie Lokier. */

/* { dg-warning "multi-line comment" 7 } */
// this \
  produces a warning;

// neither \
  // this

// nor \
//   this do, though

/* { dg-warning "multi-line comment" 18 } */
int
// this one \
  compiles
  ok;

/* { dg-warning "multi-line comment" 23 } */
// remember to handle \
/\
/ embedded newlines.

  reply	other threads:[~2000-09-25 12:52 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-09-17 15:53 Craig Rodrigues
2000-09-17 16:12 ` Jan Dvorak
2000-09-17 16:26 ` Richard Henderson
2000-09-18  3:04   ` Jamie Lokier
2000-09-19  9:05     ` Jan Dvorak
2000-09-19 10:13       ` Jamie Lokier
2000-09-19 11:44         ` Jan Dvorak
     [not found]         ` <20000919214025.A30587@daikokuya.demon.co.uk>
     [not found]           ` <20000919214320.A30677@daikokuya.demon.co.uk>
2000-09-20  8:52             ` Jamie Lokier
2000-09-20  9:38               ` Neil Booth
2000-09-25 12:52                 ` Jamie Lokier [this message]
2000-09-25 14:10                   ` Neil Booth
2000-09-25 14:34                     ` Joern Rennecke
     [not found]                   ` <20000925222224.B24101@daikokuya.demon.co.uk>
     [not found]                     ` <20000926001457.A12405@daikokuya.demon.co.uk>
2000-09-26 10:15                       ` Varargs macros subtly broken Jamie Lokier
     [not found] <20000925230543.A28863@daikokuya.demon.co.uk>
2000-09-25 15:18 ` warning: multi-line comment (why?) Joern Rennecke
2000-09-25 15:53   ` Neil Booth
2000-09-25 16:39     ` Joern Rennecke
2000-09-26  3:43     ` Jamie Lokier
2000-09-26 10:13       ` Neil Booth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20000925215143.A16833@pcep-jamie.cern.ch \
    --to=egcs@tantalophile.demon.co.uk \
    --cc=NeilB@earthling.net \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gcc@gcc.gnu.org \
    --cc=johnydog@go.cz \
    --cc=rodrigc@mediaone.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).