From: jason Date: Mon, 29 Mar 2010 15:00:43 +0000 (+0000) Subject: Some raw string changes from N3077 X-Git-Url: http://git.sourceforge.jp/view?a=commitdiff_plain;h=89b4b3271dfa3120359fffd4c2aa469c11b807b6;p=pf3gnuchains%2Fgcc-fork.git 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@157797 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e429f264eb1..e2fd72efee5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2010-03-29 Jason Merrill + + N3077 + * g++.dg/ext/raw-string-1.C: Change [] to (). + * g++.dg/ext/raw-string-2.C: Change [] to (). + Don't use \ in delimiter. + * g++.dg/ext/raw-string-3.C: Change [] to (). + * g++.dg/ext/raw-string-4.C: Change [] to (). + * g++.dg/ext/raw-string-5.C: Change [] to (). + Test for error on \ in delimiter. + * g++.dg/ext/raw-string-6.C: Change [] to (). + * g++.dg/ext/raw-string-7.C: Change [] to (). + 2010-03-29 Jie Zhang PR 43564 diff --git a/gcc/testsuite/g++.dg/ext/raw-string-1.C b/gcc/testsuite/g++.dg/ext/raw-string-1.C new file mode 100644 index 00000000000..c2426d5395f --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-1.C @@ -0,0 +1,96 @@ +// { dg-do run } +// { dg-options "-std=c++0x" } + +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 s2[] = R"*|*(a\ +b +c)" +c)*|" +c)*|*"; +const char s3[] = "ab\nc)\"\nc)*|\"\nc"; + +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 t2[] = u8R"*|*(a\ +b +c)" +c)*|" +c)*|*"; +const char t3[] = u8"ab\nc)\"\nc)*|\"\nc"; + +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 u2[] = uR"*|*(a\ +b +c)" +c)*|" +c)*|*"; +const char16_t u3[] = u"ab\nc)\"\nc)*|\"\nc"; + +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 U2[] = UR"*|*(a\ +b +c)" +c)*|" +c)*|*"; +const char32_t U3[] = U"ab\nc)\"\nc)*|\"\nc"; + +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 L2[] = LR"*|*(a\ +b +c)" +c)*|" +c)*|*"; +const wchar_t L3[] = L"ab\nc)\"\nc)*|\"\nc"; + +int +main (void) +{ + if (sizeof (s0) != sizeof (s1) + || __builtin_memcmp (s0, s1, sizeof (s0)) != 0) + __builtin_abort (); + if (sizeof (s2) != sizeof (s3) + || __builtin_memcmp (s2, s3, sizeof (s2)) != 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 (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 (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 (R"*()*") != 1 + || __builtin_memcmp (R"*()*", "", 1) != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/testsuite/g++.dg/ext/raw-string-2.C b/gcc/testsuite/g++.dg/ext/raw-string-2.C new file mode 100644 index 00000000000..d2fe9aaff42 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-2.C @@ -0,0 +1,104 @@ +// { dg-do run } +// { dg-options "-std=c++0x" } + +#define R +#define u +#define uR +#define U +#define UR +#define u8 +#define u8R +#define L +#define LR + +const char s00[] = R"(a)" "(b)"; +const char s01[] = "(a)" R"*(b)*"; +const char s02[] = R"(a)" R"(b)"; +const char s03[] = R"-(a)-" u8"(b)"; +const char s04[] = "(a)" u8R"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ"; +const char s05[] = R"(a)" u8R"wxyzABCDEFGHIJKL(b)wxyzABCDEFGHIJKL"; +const char s06[] = u8R";[(a);[" "(b)"; +const char s07[] = u8"(a)" R"(b)"; +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 char16_t u03[] = R"-(a)-" u"(b)"; +const char16_t u04[] = "(a)" uR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ"; +const char16_t u05[] = R"(a)" uR"wxyzABCDEFGHIJKL(b)wxyzABCDEFGHIJKL"; +const char16_t u06[] = uR";[(a);[" "(b)"; +const char16_t u07[] = u"(a)" R"(b)"; +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 char32_t U03[] = R"-(a)-" U"(b)"; +const char32_t U04[] = "(a)" UR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ"; +const char32_t U05[] = R"(a)" UR"wxyzABCDEFGHIJKL(b)wxyzABCDEFGHIJKL"; +const char32_t U06[] = UR";[(a);[" "(b)"; +const char32_t U07[] = U"(a)" R"(b)"; +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 wchar_t L03[] = R"-(a)-" L"(b)"; +const wchar_t L04[] = "(a)" LR"MNOPQRSTUVWXYZ(b)MNOPQRSTUVWXYZ"; +const wchar_t L05[] = R"(a)" LR"wxyzABCDEFGHIJKL(b)wxyzABCDEFGHIJKL"; +const wchar_t L06[] = LR";[(a);[" "(b)"; +const wchar_t L07[] = L"(a)" R"(b)"; +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"; + +int +main (void) +{ +#define TEST(str, val) \ + if (sizeof (str) != sizeof (val) \ + || __builtin_memcmp (str, val, sizeof (str)) != 0) \ + __builtin_abort () + TEST (s00, "a(b)"); + TEST (s01, "(a)b"); + TEST (s02, "ab"); + TEST (s03, "a(b)"); + TEST (s04, "(a)b"); + TEST (s05, "ab"); + TEST (s06, "a(b)"); + TEST (s07, "(a)b"); + TEST (s08, "ab"); + TEST (s09, "a(b)"); + TEST (s10, "(a)b"); + TEST (s11, "ab"); + TEST (u03, u"a(b)"); + TEST (u04, u"(a)b"); + TEST (u05, u"ab"); + TEST (u06, u"a(b)"); + TEST (u07, u"(a)b"); + TEST (u08, u"ab"); + TEST (u09, u"a(b)"); + TEST (u10, u"(a)b"); + TEST (u11, u"ab"); + TEST (U03, U"a(b)"); + TEST (U04, U"(a)b"); + TEST (U05, U"ab"); + TEST (U06, U"a(b)"); + TEST (U07, U"(a)b"); + TEST (U08, U"ab"); + TEST (U09, U"a(b)"); + TEST (U10, U"(a)b"); + TEST (U11, U"ab"); + TEST (L03, L"a(b)"); + TEST (L04, L"(a)b"); + TEST (L05, L"ab"); + TEST (L06, L"a(b)"); + TEST (L07, L"(a)b"); + TEST (L08, L"ab"); + TEST (L09, L"a(b)"); + TEST (L10, L"(a)b"); + TEST (L11, L"ab"); + return 0; +} diff --git a/gcc/testsuite/g++.dg/ext/raw-string-3.C b/gcc/testsuite/g++.dg/ext/raw-string-3.C new file mode 100644 index 00000000000..bb2e0c71b55 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-3.C @@ -0,0 +1,58 @@ +// If c++98, the {,u,u8,U,L}R prefix should be parsed as separate +// token. +// { dg-do compile } +// { dg-options "-std=c++98" } + +const void *s0 = R"(a)"; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 6 } +const void *s1 = uR"(a)"; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 8 } +const void *s2 = UR"(a)"; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 10 } +const void *s3 = u8R"(a)"; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 12 } +const void *s4 = LR"(a)"; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 14 } + +const int i0 = R'a'; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 17 } +const int i1 = uR'a'; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 19 } +const int i2 = UR'a'; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 21 } +const int i3 = u8R'a'; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 23 } +const int i4 = LR'a'; // { dg-error "was not declared" } + // { dg-error "expected ',' or ';'" "" { target *-*-* } 25 } + +#define R "a" +#define uR "b" +#define UR "c" +#define u8R "d" +#define LR "e" + +const void *s5 = R"(a)"; +const void *s6 = uR"(a)"; +const void *s7 = UR"(a)"; +const void *s8 = u8R"(a)"; +const void *s9 = LR"(a)"; + +#undef R +#undef uR +#undef UR +#undef u8R +#undef LR + +#define R 1 + +#define uR 2 + +#define UR 3 + +#define u8R 4 + +#define LR 5 + + +const int i5 = R'a'; +const int i6 = uR'a'; +const int i7 = UR'a'; +const int i8 = u8R'a'; +const int i9 = LR'a'; + +int main () {} diff --git a/gcc/testsuite/g++.dg/ext/raw-string-5.C b/gcc/testsuite/g++.dg/ext/raw-string-5.C new file mode 100644 index 00000000000..3808fcffea2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-5.C @@ -0,0 +1,26 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } + +const void *s0 = R"0123456789abcdefg()0123456789abcdefg"; + // { dg-error "raw string delimiter longer" "" { target *-*-* } 4 } + // { dg-error "stray" "" { target *-*-* } 4 } +const void *s1 = R" () "; + // { dg-error "invalid character" "" { target *-*-* } 7 } + // { dg-error "stray" "" { target *-*-* } 7 } +const void *s2 = R" () "; + // { dg-error "invalid character" "" { target *-*-* } 10 } + // { dg-error "stray" "" { target *-*-* } 10 } +const void *s3 = R")())"; + // { dg-error "invalid character" "" { target *-*-* } 13 } + // { dg-error "stray" "" { target *-*-* } 13 } +const void *s4 = R"@()@"; + // { dg-error "invalid character" "" { target *-*-* } 16 } + // { dg-error "stray" "" { target *-*-* } 16 } +const void *s5 = R"$()$"; + // { dg-error "invalid character" "" { target *-*-* } 19 } + // { dg-error "stray" "" { target *-*-* } 19 } +const void *s6 = R"\u0010()\u0010"; + // { dg-error "invalid character" "" { target *-*-* } 22 } + // { dg-error "stray" "" { target *-*-* } 22 } + +int main () {} diff --git a/gcc/testsuite/g++.dg/ext/raw-string-6.C b/gcc/testsuite/g++.dg/ext/raw-string-6.C new file mode 100644 index 00000000000..7906d40a1b0 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-6.C @@ -0,0 +1,5 @@ +// { dg-do compile } +// { dg-options "-std=c++0x" } + +const void *s0 = R"ouch()ouCh"; // { dg-error "at end of input" } + // { dg-error "unterminated raw string" "" { target *-*-* } 4 } diff --git a/gcc/testsuite/g++.dg/ext/raw-string-7.C b/gcc/testsuite/g++.dg/ext/raw-string-7.C new file mode 100644 index 00000000000..24737bc2865 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/raw-string-7.C @@ -0,0 +1,23 @@ +// The trailing whitespace after \ and before newline extension +// breaks full compliance for raw strings. +// { dg-do run { xfail *-*-* } } +// { dg-options "-std=c++0x" } + +// Note, there is a single space after \ on the following line. +const char *s0 = R"(\ +)"; +// { dg-bogus "backslash and newline separated by space" "" { xfail *-*-* } 7 } + +// Note, there is a single tab after \ on the following line. +const char *s1 = R"(\ +)"; +// { dg-bogus "backslash and newline separated by space" "" { xfail *-*-* } 12 } + +int +main (void) +{ + if (__builtin_strcmp (s0, "\\ \n") != 0 + || __builtin_strcmp (s1, "\\\t\n") != 0) + __builtin_abort (); + return 0; +} diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index cc77ca013bc..24030fb4c8a 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,77 +1,5 @@ -2010-04-25 Joseph Myers - - * include/cpplib.h (enum c_lang): Add CLK_GNUC1X and CLK_STDC1X. - * init.c (lang_defaults): Add entries for new language variants. - (cpp_init_builtins): Define __STDC_VERSION__ to 201000L for C1X - variants. - -2010-04-09 Manuel López-Ibáñez - - PR cpp/43195 - * files.c (report_missing_guard): Test for #pragma once. - -2010-04-07 Simon Baldwin - - * directives.c (do_diagnostic): Add warning reason argument, - call appropriate error reporting function for code. - (directive_diagnostics): Call specific warning functions with - warning reason where appropriate. - (do_error, do_warning, do_pragma_dependency): Add warning reason - argument to do_diagnostic calls. - * macro.c (_cpp_warn_if_unused_macro, enter_macro_context, - _cpp_create_definition): Call specific warning functions with - warning reason where appropriate. - * Makefile.in: Add new diagnostic functions to gettext translations. - * include/cpplib.h (struct cpp_callbacks): Add warning reason code - to error callback. - (CPP_DL_WARNING, CPP_DL_WARNING_SYSHDR, CPP_DL_PEDWARN, CPP_DL_ERROR, - CPP_DL_ICE, CPP_DL_NOTE, CPP_DL_FATAL): Replace macros with enums. - (CPP_W_NONE, CPP_W_DEPRECATED, CPP_W_COMMENTS, - CPP_W_MISSING_INCLUDE_DIRS, CPP_W_TRIGRAPHS, CPP_W_MULTICHAR, - CPP_W_TRADITIONAL, CPP_W_LONG_LONG, CPP_W_ENDIF_LABELS, - CPP_W_NUM_SIGN_CHANGE, CPP_W_VARIADIC_MACROS, - CPP_W_BUILTIN_MACRO_REDEFINED, CPP_W_DOLLARS, CPP_W_UNDEF, - CPP_W_UNUSED_MACROS, CPP_W_CXX_OPERATOR_NAMES, CPP_W_NORMALIZE, - CPP_W_INVALID_PCH, CPP_W_WARNING_DIRECTIVE): New enums for cpp - warning reason codes. - (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, - cpp_warning_with_line, cpp_pedwarning_with_line, - cpp_warning_with_line_syshdr): New specific error reporting functions. - * pch.c (cpp_valid_state): Call specific warning functions with - warning reason where appropriate. - * errors.c (cpp_diagnostic, cpp_diagnostic_with_line): New central - diagnostic handlers. - (cpp_warning, cpp_pedwarning, cpp_warning_syshdr, - cpp_warning_with_line, cpp_pedwarning_with_line, - cpp_warning_with_line_syshdr): New specific error reporting functions. - * expr.c (cpp_classify_number, eval_token, num_unary_op): Call - specific warning functions with warning reason where appropriate. - * lex.c (_cpp_process_line_notes, _cpp_skip_block_comment, - warn_about_normalization, lex_identifier_intern, lex_identifier, - _cpp_lex_direct): Ditto. - * charset.c (_cpp_valid_ucn, convert_hex, convert_escape, - narrow_str_to_charconst): Ditto. - -2010-04-06 Jakub Jelinek - - PR preprocessor/43642 - * lex.c (lex_raw_string): Change type of TYPE variable to - unsigned char. - -2010-04-02 Ralf Wildenhues - - * aclocal.m4: Regenerate. - 2010-03-29 Jason Merrill - 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. diff --git a/libcpp/lex.c b/libcpp/lex.c index f6282729946..74deab20608 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -301,23 +301,19 @@ _cpp_process_line_notes (cpp_reader *pfile, int in_comment) && (!in_comment || warn_in_comment (pfile, note))) { if (CPP_OPTION (pfile, trigraphs)) - cpp_warning_with_line (pfile, CPP_W_TRIGRAPHS, - pfile->line_table->highest_line, col, - "trigraph ??%c converted to %c", - note->type, - (int) _cpp_trigraph_map[note->type]); + cpp_error_with_line (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col, + "trigraph ??%c converted to %c", + note->type, + (int) _cpp_trigraph_map[note->type]); else { - cpp_warning_with_line - (pfile, CPP_W_TRIGRAPHS, - pfile->line_table->highest_line, col, + cpp_error_with_line + (pfile, CPP_DL_WARNING, pfile->line_table->highest_line, col, "trigraph ??%c ignored, use -trigraphs to enable", note->type); } } } - else if (note->type == 0) - /* Already processed in lex_raw_string. */; else abort (); } @@ -357,10 +353,9 @@ _cpp_skip_block_comment (cpp_reader *pfile) && cur[0] == '*' && cur[1] != '/') { buffer->cur = cur; - cpp_warning_with_line (pfile, CPP_W_COMMENTS, - pfile->line_table->highest_line, - CPP_BUF_COL (buffer), - "\"/*\" within comment"); + cpp_error_with_line (pfile, CPP_DL_WARNING, + pfile->line_table->highest_line, CPP_BUF_COL (buffer), + "\"/*\" within comment"); } } else if (c == '\n') @@ -463,11 +458,11 @@ warn_about_normalization (cpp_reader *pfile, sz = cpp_spell_token (pfile, token, buf, false) - buf; if (NORMALIZE_STATE_RESULT (s) == normalized_C) - cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0, - "`%.*s' is not in NFKC", (int) sz, buf); + cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0, + "`%.*s' is not in NFKC", (int) sz, buf); else - cpp_warning_with_line (pfile, CPP_W_NORMALIZE, token->src_loc, 0, - "`%.*s' is not in NFC", (int) sz, buf); + cpp_error_with_line (pfile, CPP_DL_WARNING, token->src_loc, 0, + "`%.*s' is not in NFC", (int) sz, buf); } } @@ -548,9 +543,9 @@ lex_identifier_intern (cpp_reader *pfile, const uchar *base) /* For -Wc++-compat, warn about use of C++ named operators. */ if (result->flags & NODE_WARN_OPERATOR) - cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES, - "identifier \"%s\" is a special operator name in C++", - NODE_NAME (result)); + cpp_error (pfile, CPP_DL_WARNING, + "identifier \"%s\" is a special operator name in C++", + NODE_NAME (result)); } return result; @@ -625,9 +620,9 @@ lex_identifier (cpp_reader *pfile, const uchar *base, bool starts_ucn, /* For -Wc++-compat, warn about use of C++ named operators. */ if (result->flags & NODE_WARN_OPERATOR) - cpp_warning (pfile, CPP_W_CXX_OPERATOR_NAMES, - "identifier \"%s\" is a special operator name in C++", - NODE_NAME (result)); + cpp_error (pfile, CPP_DL_WARNING, + "identifier \"%s\" is a special operator name in C++", + NODE_NAME (result)); } return result; @@ -679,37 +674,8 @@ create_literal (cpp_reader *pfile, cpp_token *token, const uchar *base, token->val.str.text = dest; } -/* Subroutine of lex_raw_string: Append LEN chars from BASE to the buffer - sequence from *FIRST_BUFF_P to LAST_BUFF_P. */ - -static void -bufring_append (cpp_reader *pfile, const uchar *base, size_t len, - _cpp_buff **first_buff_p, _cpp_buff **last_buff_p) -{ - _cpp_buff *first_buff = *first_buff_p; - _cpp_buff *last_buff = *last_buff_p; - - if (first_buff == NULL) - first_buff = last_buff = _cpp_get_buff (pfile, len); - else if (len > BUFF_ROOM (last_buff)) - { - size_t room = BUFF_ROOM (last_buff); - memcpy (BUFF_FRONT (last_buff), base, room); - BUFF_FRONT (last_buff) += room; - base += room; - len -= room; - last_buff = _cpp_append_extend_buff (pfile, last_buff, len); - } - - memcpy (BUFF_FRONT (last_buff), base, len); - BUFF_FRONT (last_buff) += len; - - *first_buff_p = first_buff; - *last_buff_p = last_buff; -} - /* Lexes a raw string. The stored string contains the spelling, including - double quotes, delimiter string, '(' and ')', any leading + double quotes, delimiter string, '[' and ']', any leading 'L', 'u', 'U' or 'u8' and 'R' modifier. It returns the type of the literal, or CPP_OTHER if it was not properly terminated. @@ -726,7 +692,6 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, enum cpp_ttype type; size_t total_len = 0; _cpp_buff *first_buff = NULL, *last_buff = NULL; - _cpp_line_note *note = &pfile->buffer->notes[pfile->buffer->cur_note]; type = (*base == 'L' ? CPP_WSTRING : *base == 'U' ? CPP_STRING32 : @@ -784,99 +749,7 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, cur = raw_prefix + raw_prefix_len + 1; for (;;) { -#define BUF_APPEND(STR,LEN) \ - do { \ - bufring_append (pfile, (const uchar *)(STR), (LEN), \ - &first_buff, &last_buff); \ - total_len += (LEN); \ - } while (0); - - cppchar_t c; - - /* If we previously performed any trigraph or line splicing - transformations, undo them within the body of the raw string. */ - while (note->pos < cur) - ++note; - for (; note->pos == cur; ++note) - { - switch (note->type) - { - case '\\': - case ' ': - /* Restore backslash followed by newline. */ - BUF_APPEND (base, cur - base); - base = cur; - BUF_APPEND ("\\", 1); - after_backslash: - if (note->type == ' ') - { - /* GNU backslash whitespace newline extension. FIXME - could be any sequence of non-vertical space. When we - can properly restore any such sequence, we should mark - this note as handled so _cpp_process_line_notes - doesn't warn. */ - 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. */ - uchar 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++; + cppchar_t c = *cur++; if (c == ')' && strncmp ((const char *) cur, (const char *) raw_prefix, @@ -899,14 +772,39 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, break; } - BUF_APPEND (base, cur - base); + /* raw strings allow embedded non-escaped newlines, which + complicates this routine a lot. */ + if (first_buff == NULL) + { + total_len = cur - base; + first_buff = last_buff = _cpp_get_buff (pfile, total_len); + memcpy (BUFF_FRONT (last_buff), base, total_len); + raw_prefix = BUFF_FRONT (last_buff) + (raw_prefix - base); + BUFF_FRONT (last_buff) += total_len; + } + else + { + size_t len = cur - base; + size_t cur_len = len > BUFF_ROOM (last_buff) + ? BUFF_ROOM (last_buff) : len; + + total_len += len; + memcpy (BUFF_FRONT (last_buff), base, cur_len); + BUFF_FRONT (last_buff) += cur_len; + if (len > cur_len) + { + last_buff = _cpp_append_extend_buff (pfile, last_buff, + len - cur_len); + memcpy (BUFF_FRONT (last_buff), base + cur_len, + len - cur_len); + BUFF_FRONT (last_buff) += len - cur_len; + } + } if (pfile->buffer->cur < pfile->buffer->rlimit) CPP_INCREMENT_LINE (pfile, 0); pfile->buffer->need_line = true; - pfile->buffer->cur = cur-1; - _cpp_process_line_notes (pfile, false); if (!_cpp_get_fresh_line (pfile)) { source_location src_loc = token->src_loc; @@ -922,13 +820,11 @@ lex_raw_string (cpp_reader *pfile, cpp_token *token, const uchar *base, } cur = base = pfile->buffer->cur; - note = &pfile->buffer->notes[pfile->buffer->cur_note]; } else if (c == '\0' && !saw_NUL) LINEMAP_POSITION_FOR_COLUMN (saw_NUL, pfile->line_table, CPP_BUF_COLUMN (pfile->buffer, cur)); } - break_outer_loop: if (saw_NUL && !pfile->state.skipping) cpp_error_with_line (pfile, CPP_DL_WARNING, saw_NUL, 0, @@ -1534,7 +1430,7 @@ _cpp_lex_direct (cpp_reader *pfile) } if (skip_line_comment (pfile) && CPP_OPTION (pfile, warn_comments)) - cpp_warning (pfile, CPP_W_COMMENTS, "multi-line comment"); + cpp_error (pfile, CPP_DL_WARNING, "multi-line comment"); } else if (c == '=') {