OSDN Git Service

More N3077 raw string changes
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 29 Mar 2010 20:07:29 +0000 (20:07 +0000)
committerMasaki Muranaka <monaka@monami-software.com>
Sun, 23 May 2010 05:15:15 +0000 (14:15 +0900)
* charset.c (cpp_interpret_string): Don't transform UCNs in raw
strings.
* lex.c (bufring_append): Split out from...
(lex_raw_string): ...here.  Undo trigraph and line splicing
transformations.  Do process line notes in multi-line literals.
(_cpp_process_line_notes): Ignore notes that were already handled.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157804 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/raw-string-1.c
gcc/testsuite/c-c++-common/raw-string-2.c
libcpp/ChangeLog
libcpp/lex.c

index da04f41..4693a70 100644 (file)
@@ -1,5 +1,13 @@
 2010-03-29  Jason Merrill  <jason@redhat.com>
 
 2010-03-29  Jason Merrill  <jason@redhat.com>
 
+       N3077
+       * c-c++-common/raw-string-1.c: Update handling of trigraphs, line
+       splicing and UCNs.
+       * c-c++-common/raw-string-2.c: Add trigraph test.
+       * c-c++-common/raw-string-8.c: New.
+       * c-c++-common/raw-string-9.c: New.
+       * c-c++-common/raw-string-10.c: New.
+
        * c-c++-common/raw-string-1.c: Combine C and C++ raw string tests.
        * c-c++-common/raw-string-2.c: Combine C and C++ raw string tests.
        * c-c++-common/raw-string-3.c: Combine C and C++ raw string tests.
        * c-c++-common/raw-string-1.c: Combine C and C++ raw string tests.
        * c-c++-common/raw-string-2.c: Combine C and C++ raw string tests.
        * c-c++-common/raw-string-3.c: Combine C and C++ raw string tests.
index b790a31..199a3c6 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-do run }
 // { dg-require-effective-target wchar }
 // { dg-do run }
 // { dg-require-effective-target wchar }
-// { dg-options "-std=gnu99 -Wno-c++-compat" { target c } }
+// { dg-options "-std=gnu99 -Wno-c++-compat -trigraphs" { target c } }
 // { dg-options "-std=c++0x" { target c++ } }
 
 #ifndef __cplusplus
 // { dg-options "-std=c++0x" { target c++ } }
 
 #ifndef __cplusplus
@@ -13,57 +13,78 @@ typedef __CHAR32_TYPE__ char32_t;
 const char s0[] = R"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
 const char s0[] = R"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
-const char s1[] = "a\U0000010d\u010d\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
+const char s1[] = "a\\\n\\u010d\\U0000010D\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
 const char s2[] = R"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
 const char s2[] = R"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
-const char s3[] = "ab\nc)\"\nc)*|\"\nc";
+const char s3[] = "a\\\nb\nc)\"\nc)*|\"\nc";
+// The ) in ??) below is part of the raw string suffix )".
+const char s4[] = R"(??/
+??/
+??(??<??=??'??!??-??>??)";
+const char s5[] = "?\?/\n?\?/\n?\?(?\?<?\?=?\?'?\?!?\?-?\?>?\?";
 
 const char t0[] = u8R"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
 
 const char t0[] = u8R"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
-const char t1[] = u8"a\U0000010d\u010d\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
+const char t1[] = u8"a\\\n\\u010d\\U0000010D\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
 const char t2[] = u8R"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
 const char t2[] = u8R"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
-const char t3[] = u8"ab\nc)\"\nc)*|\"\nc";
+const char t3[] = u8"a\\\nb\nc)\"\nc)*|\"\nc";
+const char t4[] = u8R"(??/
+??/
+??(??<??=??'??!??-??>??)";
+const char t5[] = u8"?\?/\n?\?/\n?\?(?\?<?\?=?\?'?\?!?\?-?\?>?\?";
 
 const char16_t u0[] = uR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
 
 const char16_t u0[] = uR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
-const char16_t u1[] = u"a\U0000010d\u010d\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
+const char16_t u1[] = u"a\\\n\\u010d\\U0000010D\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
 const char16_t u2[] = uR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
 const char16_t u2[] = uR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
-const char16_t u3[] = u"ab\nc)\"\nc)*|\"\nc";
+const char16_t u3[] = u"a\\\nb\nc)\"\nc)*|\"\nc";
+const char16_t u4[] = uR"(??/
+??/
+??(??<??=??'??!??-??>??)";
+const char16_t u5[] = u"?\?/\n?\?/\n?\?(?\?<?\?=?\?'?\?!?\?-?\?>?\?";
 
 const char32_t U0[] = UR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
 
 const char32_t U0[] = UR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
-const char32_t U1[] = U"a\U0000010d\u010d\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
+const char32_t U1[] = U"a\\\n\\u010d\\U0000010D\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
 const char32_t U2[] = UR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
 const char32_t U2[] = UR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
-const char32_t U3[] = U"ab\nc)\"\nc)*|\"\nc";
+const char32_t U3[] = U"a\\\nb\nc)\"\nc)*|\"\nc";
+const char32_t U4[] = UR"(??/
+??/
+??(??<??=??'??!??-??>??)";
+const char32_t U5[] = U"?\?/\n?\?/\n?\?(?\?<?\?=?\?'?\?!?\?-?\?>?\?";
 
 const wchar_t L0[] = LR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
 
 const wchar_t L0[] = LR"(a\
 \u010d\U0000010D\\\'\"\?\a\b\f\n\r\t\v\0\00\000\xa\xabb
 c)";
-const wchar_t L1[] = L"a\U0000010d\u010d\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
+const wchar_t L1[] = L"a\\\n\\u010d\\U0000010D\\\\\\'\\\"\\?\\a\\b\\f\\n\\r\\t\\v\\0\\00\\000\\xa\\xabb\nc";
 const wchar_t L2[] = LR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
 const wchar_t L2[] = LR"*|*(a\
 b
 c)"
 c)*|"
 c)*|*";
-const wchar_t L3[] = L"ab\nc)\"\nc)*|\"\nc";
+const wchar_t L3[] = L"a\\\nb\nc)\"\nc)*|\"\nc";
+const wchar_t L4[] = LR"(??/
+??/
+??(??<??=??'??!??-??>??)";
+const wchar_t L5[] = L"?\?/\n?\?/\n?\?(?\?<?\?=?\?'?\?!?\?-?\?>?\?";
 
 int
 main (void)
 
 int
 main (void)
@@ -74,30 +95,45 @@ main (void)
   if (sizeof (s2) != sizeof (s3)
       || __builtin_memcmp (s2, s3, sizeof (s2)) != 0)
     __builtin_abort ();
   if (sizeof (s2) != sizeof (s3)
       || __builtin_memcmp (s2, s3, sizeof (s2)) != 0)
     __builtin_abort ();
+  if (sizeof (s4) != sizeof (s5)
+      || __builtin_memcmp (s4, s5, sizeof (s4)) != 0)
+    __builtin_abort ();
   if (sizeof (t0) != sizeof (t1)
       || __builtin_memcmp (t0, t1, sizeof (t0)) != 0)
     __builtin_abort ();
   if (sizeof (t2) != sizeof (t3)
       || __builtin_memcmp (t2, t3, sizeof (t2)) != 0)
     __builtin_abort ();
   if (sizeof (t0) != sizeof (t1)
       || __builtin_memcmp (t0, t1, sizeof (t0)) != 0)
     __builtin_abort ();
   if (sizeof (t2) != sizeof (t3)
       || __builtin_memcmp (t2, t3, sizeof (t2)) != 0)
     __builtin_abort ();
+  if (sizeof (t4) != sizeof (t5)
+      || __builtin_memcmp (t4, t5, sizeof (t4)) != 0)
+    __builtin_abort ();
   if (sizeof (u0) != sizeof (u1)
       || __builtin_memcmp (u0, u1, sizeof (u0)) != 0)
     __builtin_abort ();
   if (sizeof (u2) != sizeof (u3)
       || __builtin_memcmp (u2, u3, sizeof (u2)) != 0)
     __builtin_abort ();
   if (sizeof (u0) != sizeof (u1)
       || __builtin_memcmp (u0, u1, sizeof (u0)) != 0)
     __builtin_abort ();
   if (sizeof (u2) != sizeof (u3)
       || __builtin_memcmp (u2, u3, sizeof (u2)) != 0)
     __builtin_abort ();
+  if (sizeof (u4) != sizeof (u5)
+      || __builtin_memcmp (u4, u5, sizeof (u4)) != 0)
+    __builtin_abort ();
   if (sizeof (U0) != sizeof (U1)
       || __builtin_memcmp (U0, U1, sizeof (U0)) != 0)
     __builtin_abort ();
   if (sizeof (U2) != sizeof (U3)
       || __builtin_memcmp (U2, U3, sizeof (U2)) != 0)
     __builtin_abort ();
   if (sizeof (U0) != sizeof (U1)
       || __builtin_memcmp (U0, U1, sizeof (U0)) != 0)
     __builtin_abort ();
   if (sizeof (U2) != sizeof (U3)
       || __builtin_memcmp (U2, U3, sizeof (U2)) != 0)
     __builtin_abort ();
+  if (sizeof (U4) != sizeof (U5)
+      || __builtin_memcmp (U4, U5, sizeof (U4)) != 0)
+    __builtin_abort ();
   if (sizeof (L0) != sizeof (L1)
       || __builtin_memcmp (L0, L1, sizeof (L0)) != 0)
     __builtin_abort ();
   if (sizeof (L2) != sizeof (L3)
       || __builtin_memcmp (L2, L3, sizeof (L2)) != 0)
     __builtin_abort ();
   if (sizeof (L0) != sizeof (L1)
       || __builtin_memcmp (L0, L1, sizeof (L0)) != 0)
     __builtin_abort ();
   if (sizeof (L2) != sizeof (L3)
       || __builtin_memcmp (L2, L3, sizeof (L2)) != 0)
     __builtin_abort ();
+  if (sizeof (L4) != sizeof (L5)
+      || __builtin_memcmp (L4, L5, sizeof (L4)) != 0)
+    __builtin_abort ();
   if (sizeof (R"*()*") != 1
       || __builtin_memcmp (R"*()*", "", 1) != 0)
     __builtin_abort ();
   if (sizeof (R"*()*") != 1
       || __builtin_memcmp (R"*()*", "", 1) != 0)
     __builtin_abort ();
index 503bcf5..e296a08 100644 (file)
@@ -1,6 +1,6 @@
 // { dg-do run }
 // { dg-require-effective-target wchar }
 // { dg-do run }
 // { dg-require-effective-target wchar }
-// { dg-options "-std=gnu99 -Wno-c++-compat" { target c } }
+// { dg-options "-std=gnu99 -Wno-c++-compat -trigraphs" { target c } }
 // { dg-options "-std=c++0x" { target c++ } }
 
 #ifndef __cplusplus
 // { dg-options "-std=c++0x" { target c++ } }
 
 #ifndef __cplusplus
@@ -32,6 +32,8 @@ const char s08[] = u8R"(a)" R"_{}#[]<>%:;.?*+-(b)_{}#[]<>%:;.?*+-";
 const char s09[] = u8R"/^&|~!=,"'(a)/^&|~!=,"'" u8"(b)";
 const char s10[] = u8"(a)" u8R"0123456789abcdef(b)0123456789abcdef";
 const char s11[] = u8R"ghijklmnopqrstuv(a)ghijklmnopqrstuv" u8R"w(b)w";
 const char s09[] = u8R"/^&|~!=,"'(a)/^&|~!=,"'" u8"(b)";
 const char s10[] = u8"(a)" u8R"0123456789abcdef(b)0123456789abcdef";
 const char s11[] = u8R"ghijklmnopqrstuv(a)ghijklmnopqrstuv" u8R"w(b)w";
+const char s12[] = R"??=??(??<??>??)??'??!??-\
+(a)#[{}]^|~";
 
 const char16_t u03[] = R"-(a)-" u"(b)";
 const char16_t u04[] = "(a)" uR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
 
 const char16_t u03[] = R"-(a)-" u"(b)";
 const char16_t u04[] = "(a)" uR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
@@ -42,6 +44,8 @@ const char16_t u08[] = uR"(a)" R"_{}#[]<>%:;.?*+-(b)_{}#[]<>%:;.?*+-";
 const char16_t u09[] = uR"/^&|~!=,"'(a)/^&|~!=,"'" u"(b)";
 const char16_t u10[] = u"(a)" uR"0123456789abcdef(b)0123456789abcdef";
 const char16_t u11[] = uR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" uR"w(b)w";
 const char16_t u09[] = uR"/^&|~!=,"'(a)/^&|~!=,"'" u"(b)";
 const char16_t u10[] = u"(a)" uR"0123456789abcdef(b)0123456789abcdef";
 const char16_t u11[] = uR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" uR"w(b)w";
+const char16_t u12[] = uR"??=??(??<??>??)??'??!??-\
+(a)#[{}]^|~";
 
 const char32_t U03[] = R"-(a)-" U"(b)";
 const char32_t U04[] = "(a)" UR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
 
 const char32_t U03[] = R"-(a)-" U"(b)";
 const char32_t U04[] = "(a)" UR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
@@ -52,6 +56,8 @@ const char32_t U08[] = UR"(a)" R"_{}#[]<>%:;.?*+-(b)_{}#[]<>%:;.?*+-";
 const char32_t U09[] = UR"/^&|~!=,"'(a)/^&|~!=,"'" U"(b)";
 const char32_t U10[] = U"(a)" UR"0123456789abcdef(b)0123456789abcdef";
 const char32_t U11[] = UR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" UR"w(b)w";
 const char32_t U09[] = UR"/^&|~!=,"'(a)/^&|~!=,"'" U"(b)";
 const char32_t U10[] = U"(a)" UR"0123456789abcdef(b)0123456789abcdef";
 const char32_t U11[] = UR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" UR"w(b)w";
+const char32_t U12[] = UR"??=??(??<??>??)??'??!??-\
+(a)#[{}]^|~";
 
 const wchar_t L03[] = R"-(a)-" L"(b)";
 const wchar_t L04[] = "(a)" LR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
 
 const wchar_t L03[] = R"-(a)-" L"(b)";
 const wchar_t L04[] = "(a)" LR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ";
@@ -62,6 +68,8 @@ const wchar_t L08[] = LR"(a)" R"_{}#[]<>%:;.?*+-(b)_{}#[]<>%:;.?*+-";
 const wchar_t L09[] = LR"/^&|~!=,"'(a)/^&|~!=,"'" L"(b)";
 const wchar_t L10[] = L"(a)" LR"0123456789abcdef(b)0123456789abcdef";
 const wchar_t L11[] = LR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" LR"w(b)w";
 const wchar_t L09[] = LR"/^&|~!=,"'(a)/^&|~!=,"'" L"(b)";
 const wchar_t L10[] = L"(a)" LR"0123456789abcdef(b)0123456789abcdef";
 const wchar_t L11[] = LR"ghijklmnopqrstuv(a)ghijklmnopqrstuv" LR"w(b)w";
+const wchar_t L12[] = LR"??=??(??<??>??)??'??!??-\
+(a)#[{}]^|~";
 
 int
 main (void)
 
 int
 main (void)
@@ -82,6 +90,7 @@ main (void)
   TEST (s09, "a(b)");
   TEST (s10, "(a)b");
   TEST (s11, "ab");
   TEST (s09, "a(b)");
   TEST (s10, "(a)b");
   TEST (s11, "ab");
+  TEST (s12, "a");
   TEST (u03, u"a(b)");
   TEST (u04, u"(a)b");
   TEST (u05, u"ab");
   TEST (u03, u"a(b)");
   TEST (u04, u"(a)b");
   TEST (u05, u"ab");
@@ -91,6 +100,7 @@ main (void)
   TEST (u09, u"a(b)");
   TEST (u10, u"(a)b");
   TEST (u11, u"ab");
   TEST (u09, u"a(b)");
   TEST (u10, u"(a)b");
   TEST (u11, u"ab");
+  TEST (u12, u"a");
   TEST (U03, U"a(b)");
   TEST (U04, U"(a)b");
   TEST (U05, U"ab");
   TEST (U03, U"a(b)");
   TEST (U04, U"(a)b");
   TEST (U05, U"ab");
@@ -100,6 +110,7 @@ main (void)
   TEST (U09, U"a(b)");
   TEST (U10, U"(a)b");
   TEST (U11, U"ab");
   TEST (U09, U"a(b)");
   TEST (U10, U"(a)b");
   TEST (U11, U"ab");
+  TEST (U12, U"a");
   TEST (L03, L"a(b)");
   TEST (L04, L"(a)b");
   TEST (L05, L"ab");
   TEST (L03, L"a(b)");
   TEST (L04, L"(a)b");
   TEST (L05, L"ab");
@@ -109,5 +120,6 @@ main (void)
   TEST (L09, L"a(b)");
   TEST (L10, L"(a)b");
   TEST (L11, L"ab");
   TEST (L09, L"a(b)");
   TEST (L10, L"(a)b");
   TEST (L11, L"ab");
+  TEST (L12, L"a");
   return 0;
 }
   return 0;
 }
index 24030fb..ab115d5 100644 (file)
@@ -1,5 +1,13 @@
 2010-03-29  Jason Merrill  <jason@redhat.com>
 
 2010-03-29  Jason Merrill  <jason@redhat.com>
 
+       More N3077 raw string changes
+       * charset.c (cpp_interpret_string): Don't transform UCNs in raw
+       strings.
+       * lex.c (bufring_append): Split out from...
+       (lex_raw_string): ...here.  Undo trigraph and line splicing
+       transformations.  Do process line notes in multi-line literals.
+       (_cpp_process_line_notes): Ignore notes that were already handled.
+
        Some raw string changes from N3077
        * charset.c (cpp_interpret_string): Change inner delimiters to ().
        * lex.c (lex_raw_string): Likewise.  Also disallow '\' in delimiter.
        Some raw string changes from N3077
        * charset.c (cpp_interpret_string): Change inner delimiters to ().
        * lex.c (lex_raw_string): Likewise.  Also disallow '\' in delimiter.
index 6afb220..621b9a6 100644 (file)
@@ -818,6 +818,66 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base,
                  BUF_APPEND (" ", 1);
                }
 
                  BUF_APPEND (" ", 1);
                }
 
+             BUF_APPEND ("\n", 1);
+             break;
+
+           case 0:
+             /* Already handled.  */
+             break;
+
+           default:
+             if (_cpp_trigraph_map[note->type])
+               {
+                 /* Don't warn about this trigraph in
+                    _cpp_process_line_notes, since trigraphs show up as
+                    trigraphs in raw strings.  */
+                 unsigned type = note->type;
+                 note->type = 0;
+
+                 if (!CPP_OPTION (pfile, trigraphs))
+                   /* If we didn't convert the trigraph in the first
+                      place, don't do anything now either.  */
+                   break;
+
+                 BUF_APPEND (base, cur - base);
+                 base = cur;
+                 BUF_APPEND ("??", 2);
+
+                 /* ??/ followed by newline gets two line notes, one for
+                    the trigraph and one for the backslash/newline.  */
+                 if (type == '/' && note[1].pos == cur)
+                   {
+                     if (note[1].type != '\\'
+                         && note[1].type != ' ')
+                       abort ();
+                     BUF_APPEND ("/", 1);
+                     ++note;
+                     goto after_backslash;
+                   }
+                 /* The ) from ??) could be part of the suffix.  */
+                 else if (type == ')'
+                          && strncmp ((const char *) cur+1,
+                                      (const char *) raw_prefix,
+                                      raw_prefix_len) == 0
+                          && cur[raw_prefix_len+1] == '"')
+                   {
+                     cur += raw_prefix_len+2;
+                     goto break_outer_loop;
+                   }
+                 else
+                   {
+                     /* Skip the replacement character.  */
+                     base = ++cur;
+                     BUF_APPEND (&type, 1);
+                   }
+               }
+             else
+               abort ();
+             break;
+           }
+       }
+      c = *cur++;
+
       if (c == ')'
          && strncmp ((const char *) cur, (const char *) raw_prefix,
                      raw_prefix_len) == 0
       if (c == ')'
          && strncmp ((const char *) cur, (const char *) raw_prefix,
                      raw_prefix_len) == 0