Fix locations within raw strings
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 17 Nov 2016 15:55:26 +0000 (15:55 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 17 Nov 2016 15:55:26 +0000 (15:55 +0000)
commitb8f564124ed51964b704452e3ea05b2423446e1c
treec847c4257bce9fb3b4aec31453d07ca3f78bf42f
parent141a3ccff1f53ca8a86453fbe4eaa1bc6b64d920
Fix locations within raw strings

Whilst investigating PR preprocessor/78324 I noticed that the
substring location code currently doesn't handle raw strings
correctly, by not skipping the 'R', opening quote, delimiter
and opening parenthesis.

For example, an attempt to underline chars 4-7 with caret at 6 of
this raw string yields this erroneous output:
   __emit_string_literal_range (R"foo(0123456789)foo",
                                    ~~^~

With the patch, the correct range/caret is printed:

   __emit_string_literal_range (R"foo(0123456789)foo",
                                          ~~^~

gcc/ChangeLog:
* input.c (selftest::test_lexer_string_locations_long_line): New
function.
(selftest::test_lexer_string_locations_raw_string_multiline): New
function.
(selftest::input_c_tests): Call the new functions, via
for_each_line_table_case.

gcc/testsuite/ChangeLog:
* gcc.dg/plugin/diagnostic-test-string-literals-1.c
(test_raw_string_one_liner): New function.
(test_raw_string_multiline): New function.

libcpp/ChangeLog:
* charset.c (cpp_interpret_string_1): Skip locations from
loc_reader when advancing 'p' when handling raw strings.

From-SVN: r242552
gcc/ChangeLog
gcc/input.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/plugin/diagnostic-test-string-literals-1.c
libcpp/ChangeLog
libcpp/charset.c