aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Tietz <kai.tietz@onevision.com>2010-11-16 19:50:17 +0000
committerKai Tietz <ktietz@gcc.gnu.org>2010-11-16 20:50:17 +0100
commit651a20b54b07324c321f79f98251fa2ea2d0ec54 (patch)
treeebbcc53e1ea71b17a6fce551096e1ece0b1a930e
parent92cf7399963ad4a80e4b70fe568e000155ad1f76 (diff)
downloadgcc-651a20b54b07324c321f79f98251fa2ea2d0ec54.zip
gcc-651a20b54b07324c321f79f98251fa2ea2d0ec54.tar.gz
gcc-651a20b54b07324c321f79f98251fa2ea2d0ec54.tar.bz2
re PR preprocessor/17349 (// comments cause weird behaviour with options -E -C)
2010-11-16 Kai Tietz <kai.tietz@onevision.com> PR preprocessor/17349 * lex.c (save_comment): Handle in argument passing c++ comments special. 2010-11-16 Kai Tietz <kai.tietz@onevision.com> PR preprocessor/17349 * gcc.dg/cpp/cmdlne-C3.c: New. From-SVN: r166817
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c13
-rw-r--r--libcpp/ChangeLog6
-rw-r--r--libcpp/lex.c18
4 files changed, 36 insertions, 6 deletions
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1ffbb15..fd40483 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2010-11-16 Kai Tietz <kai.tietz@onevision.com>
+
+ PR preprocessor/17349
+ * gcc.dg/cpp/cmdlne-C3.c: New.
+
2010-11-16 Richard Guenther <rguenther@suse.de>
PR tree-optimization/44545
diff --git a/gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c b/gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c
new file mode 100644
index 0000000..86a9422
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/cpp/cmdlne-C3.c
@@ -0,0 +1,13 @@
+/* { dg-do preprocess } */
+/* { dg-options "-C -P" } */
+
+#define macro(X) X
+
+macro(
+// Comment1
+x
+// Comment2
+);
+
+/* { dg-final { scan-file cmdlne-C3.i "\\\*\\\/ x \\\/\\\*" } } */
+
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index afaca8a..ec0602a 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,9 @@
+2010-11-16 Kai Tietz <kai.tietz@onevision.com>
+
+ PR preprocessor/17349
+ * lex.c (save_comment): Handle in argument passing c++
+ comments special.
+
2010-11-02 Ian Lance Taylor <iant@google.com>
* configure.ac: Use AC_SYS_LARGEFILE.
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 2e962a7..5cd5686 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -1641,7 +1641,7 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
cppchar_t type)
{
unsigned char *buffer;
- unsigned int len, clen;
+ unsigned int len, clen, i;
len = pfile->buffer->cur - from + 1; /* + 1 for the initial '/'. */
@@ -1650,13 +1650,14 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
if (is_vspace (pfile->buffer->cur[-1]))
len--;
- /* If we are currently in a directive, then we need to store all
- C++ comments as C comments internally, and so we need to
- allocate a little extra space in that case.
+ /* If we are currently in a directive or in argument parsing, then
+ we need to store all C++ comments as C comments internally, and
+ so we need to allocate a little extra space in that case.
Note that the only time we encounter a directive here is
when we are saving comments in a "#define". */
- clen = (pfile->state.in_directive && type == '/') ? len + 2 : len;
+ clen = ((pfile->state.in_directive || pfile->state.parsing_args)
+ && type == '/') ? len + 2 : len;
buffer = _cpp_unaligned_alloc (pfile, clen);
@@ -1668,11 +1669,16 @@ save_comment (cpp_reader *pfile, cpp_token *token, const unsigned char *from,
memcpy (buffer + 1, from, len - 1);
/* Finish conversion to a C comment, if necessary. */
- if (pfile->state.in_directive && type == '/')
+ if ((pfile->state.in_directive || pfile->state.parsing_args) && type == '/')
{
buffer[1] = '*';
buffer[clen - 2] = '*';
buffer[clen - 1] = '/';
+ /* As there can be in a C++ comments illegal sequences for C comments
+ we need to filter them out. */
+ for (i = 2; i < (clen - 2); i++)
+ if (buffer[i] == '/' && (buffer[i - 1] == '*' || buffer[i + 1] == '*'))
+ buffer[i] = '|';
}
/* Finally store this comment for use by clients of libcpp. */