From 87e356bada28a71fd101dce4512564ff6cb8fb15 Mon Sep 17 00:00:00 2001
From: Jakub Jelinek <jakub@redhat.com>
Date: Wed, 10 Jul 2013 18:40:49 +0200
Subject: [PATCH] re PR preprocessor/57757 (CPP extra inserted whitespace needs
 to be reviewed for C++11 user-defined literals)

	PR preprocessor/57757
	* lex.c (cpp_avoid_paste): Avoid pasting CPP_{,W,UTF8}STRING
	or CPP_STRING{16,32} with CPP_NAME or SPELL_LITERAL token that
	starts if a-zA-Z_.

	* g++.dg/cpp/paste1.C: New test.
	* g++.dg/cpp/paste2.C: New test.

From-SVN: r200875
---
 gcc/testsuite/ChangeLog           |  7 +++++++
 gcc/testsuite/g++.dg/cpp/paste1.C | 14 ++++++++++++++
 gcc/testsuite/g++.dg/cpp/paste2.C | 15 +++++++++++++++
 libcpp/ChangeLog                  |  7 +++++++
 libcpp/lex.c                      |  9 +++++++++
 5 files changed, 52 insertions(+)
 create mode 100644 gcc/testsuite/g++.dg/cpp/paste1.C
 create mode 100644 gcc/testsuite/g++.dg/cpp/paste2.C

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 1b4e046c4394..82502f5f9015 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,4 +1,11 @@
+2013-07-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR preprocessor/57757
+	* g++.dg/cpp/paste1.C: New test.
+	* g++.dg/cpp/paste2.C: New test.
+
 2013-07-10  Graham Stott  <grahams@btinternet.com>
+
 	* gcc.target/mips/mulsize-1.c: New.
 	* gcc.target/mips/mulsize-2.c: New.
 	* gcc.target/mips/mulsize-3.c: New.
diff --git a/gcc/testsuite/g++.dg/cpp/paste1.C b/gcc/testsuite/g++.dg/cpp/paste1.C
new file mode 100644
index 000000000000..a33fdf5c436a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/paste1.C
@@ -0,0 +1,14 @@
+// PR preprocessor/57757
+// { dg-do compile }
+// { dg-options "-std=c++11" }
+
+#define S(x) x
+extern S("C")void exit (int);
+int
+main ()
+{
+  (void) (S("foo")and 0);
+  const wchar_t *p = S(L"foo")L"bar";
+  const char *a = S("foo")R"(bar)";
+  exit (0);
+}
diff --git a/gcc/testsuite/g++.dg/cpp/paste2.C b/gcc/testsuite/g++.dg/cpp/paste2.C
new file mode 100644
index 000000000000..89a659e6bb95
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp/paste2.C
@@ -0,0 +1,15 @@
+// PR preprocessor/57757
+// { dg-do compile }
+// { dg-options "-std=c++11 -save-temps" }
+// { dg-final cleanup-saved-temps }
+
+#define S(x) x
+extern S("C")void exit (int);
+int
+main ()
+{
+  (void) (S("foo")and 0);
+  const wchar_t *p = S(L"foo")L"bar";
+  const char *a = S("foo")R"(bar)";
+  exit (0);
+}
diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog
index 0cf9100cf62f..d0c583d86913 100644
--- a/libcpp/ChangeLog
+++ b/libcpp/ChangeLog
@@ -1,3 +1,10 @@
+2013-07-10  Jakub Jelinek  <jakub@redhat.com>
+
+	PR preprocessor/57757
+	* lex.c (cpp_avoid_paste): Avoid pasting CPP_{,W,UTF8}STRING
+	or CPP_STRING{16,32} with CPP_NAME or SPELL_LITERAL token that
+	starts if a-zA-Z_.
+
 2013-06-28  Ed Smith-Rowland  <3dw4rd@verizon.net>
 
 	* lex.c (lex_raw_string(), lex_string()): Constrain suffixes treated
diff --git a/libcpp/lex.c b/libcpp/lex.c
index 022d31016e22..dc7b9c17ddc3 100644
--- a/libcpp/lex.c
+++ b/libcpp/lex.c
@@ -2767,6 +2767,15 @@ cpp_avoid_paste (cpp_reader *pfile, const cpp_token *token1,
 				|| (CPP_OPTION (pfile, objc)
 				    && token1->val.str.text[0] == '@'
 				    && (b == CPP_NAME || b == CPP_STRING)));
+    case CPP_STRING:
+    case CPP_WSTRING:
+    case CPP_UTF8STRING:
+    case CPP_STRING16:
+    case CPP_STRING32:	return (CPP_OPTION (pfile, user_literals)
+				&& (b == CPP_NAME
+				    || (TOKEN_SPELL (token2) == SPELL_LITERAL
+					&& ISIDST (token2->val.str.text[0]))));
+
     default:		break;
     }
 
-- 
GitLab