diff options
author | David Malcolm <dmalcolm@redhat.com> | 2016-11-17 15:55:26 +0000 |
---|---|---|
committer | David Malcolm <dmalcolm@gcc.gnu.org> | 2016-11-17 15:55:26 +0000 |
commit | b8f564124ed51964b704452e3ea05b2423446e1c (patch) | |
tree | c847c4257bce9fb3b4aec31453d07ca3f78bf42f /libcpp/charset.c | |
parent | 141a3ccff1f53ca8a86453fbe4eaa1bc6b64d920 (diff) | |
download | gcc-b8f564124ed51964b704452e3ea05b2423446e1c.zip gcc-b8f564124ed51964b704452e3ea05b2423446e1c.tar.gz gcc-b8f564124ed51964b704452e3ea05b2423446e1c.tar.bz2 |
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
Diffstat (limited to 'libcpp/charset.c')
-rw-r--r-- | libcpp/charset.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/libcpp/charset.c b/libcpp/charset.c index e77270a..9cd1e10 100644 --- a/libcpp/charset.c +++ b/libcpp/charset.c @@ -1564,10 +1564,21 @@ cpp_interpret_string_1 (cpp_reader *pfile, const cpp_string *from, size_t count, /* Skip over 'R"'. */ p += 2; + if (loc_reader) + { + loc_reader->get_next (); + loc_reader->get_next (); + } prefix = p; while (*p != '(') - p++; + { + p++; + if (loc_reader) + loc_reader->get_next (); + } p++; + if (loc_reader) + loc_reader->get_next (); limit = from[i].text + from[i].len; if (limit >= p + (p - prefix) + 1) limit -= (p - prefix) + 1; |