This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: warning: multi-line comment (why?)
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.