Skip to content

Commit 651a20b

Browse files
Kai TietzKai Tietz
authored andcommitted
re PR preprocessor/17349 (// comments cause weird behaviour with options -E -C)
2010-11-16 Kai Tietz <[email protected]> PR preprocessor/17349 * lex.c (save_comment): Handle in argument passing c++ comments special. 2010-11-16 Kai Tietz <[email protected]> PR preprocessor/17349 * gcc.dg/cpp/cmdlne-C3.c: New. From-SVN: r166817
1 parent 92cf739 commit 651a20b

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

gcc/testsuite/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2010-11-16 Kai Tietz <[email protected]>
2+
3+
PR preprocessor/17349
4+
* gcc.dg/cpp/cmdlne-C3.c: New.
5+
16
2010-11-16 Richard Guenther <[email protected]>
27

38
PR tree-optimization/44545

gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* { dg-do preprocess } */
2+
/* { dg-options "-C -P" } */
3+
4+
#define macro(X) X
5+
6+
macro(
7+
// Comment1
8+
x
9+
// Comment2
10+
);
11+
12+
/* { dg-final { scan-file cmdlne-C3.i "\\\*\\\/ x \\\/\\\*" } } */
13+

libcpp/ChangeLog

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2010-11-16 Kai Tietz <[email protected]>
2+
3+
PR preprocessor/17349
4+
* lex.c (save_comment): Handle in argument passing c++
5+
comments special.
6+
17
2010-11-02 Ian Lance Taylor <[email protected]>
28

39
* configure.ac: Use AC_SYS_LARGEFILE.

libcpp/lex.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,7 +1641,7 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
16411641
cppchar_t type)
16421642
{
16431643
unsigned char *buffer;
1644-
unsigned int len, clen;
1644+
unsigned int len, clen, i;
16451645

16461646
len = pfile->buffer->cur - from + 1; /* + 1 for the initial '/'. */
16471647

@@ -1650,13 +1650,14 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
16501650
if (is_vspace (pfile->buffer->cur[-1]))
16511651
len--;
16521652

1653-
/* If we are currently in a directive, then we need to store all
1654-
C++ comments as C comments internally, and so we need to
1655-
allocate a little extra space in that case.
1653+
/* If we are currently in a directive or in argument parsing, then
1654+
we need to store all C++ comments as C comments internally, and
1655+
so we need to allocate a little extra space in that case.
16561656
16571657
Note that the only time we encounter a directive here is
16581658
when we are saving comments in a "#define". */
1659-
clen = (pfile->state.in_directive && type == '/') ? len + 2 : len;
1659+
clen = ((pfile->state.in_directive || pfile->state.parsing_args)
1660+
&& type == '/') ? len + 2 : len;
16601661

16611662
buffer = _cpp_unaligned_alloc (pfile, clen);
16621663

@@ -1668,11 +1669,16 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
16681669
memcpy (buffer + 1, from, len - 1);
16691670

16701671
/* Finish conversion to a C comment, if necessary. */
1671-
if (pfile->state.in_directive && type == '/')
1672+
if ((pfile->state.in_directive || pfile->state.parsing_args) && type == '/')
16721673
{
16731674
buffer[1] = '*';
16741675
buffer[clen - 2] = '*';
16751676
buffer[clen - 1] = '/';
1677+
/* As there can be in a C++ comments illegal sequences for C comments
1678+
we need to filter them out. */
1679+
for (i = 2; i < (clen - 2); i++)
1680+
if (buffer[i] == '/' && (buffer[i - 1] == '*' || buffer[i + 1] == '*'))
1681+
buffer[i] = '|';
16761682
}
16771683

16781684
/* Finally store this comment for use by clients of libcpp. */

0 commit comments

Comments
 (0)