c++: libcpp: Support raw strings with newlines in directives [PR55971]
authorLewis Hyatt <lhyatt@gmail.com>
Wed, 15 Jun 2022 22:06:53 +0000 (18:06 -0400)
committerLewis Hyatt <lhyatt@gmail.com>
Sat, 5 Nov 2022 14:23:20 +0000 (10:23 -0400)
commit3ad2167bbac8ae83b1e91305b105ab5287bdac55
treed6dbb86c53a6eded2fb209819e466b6ef1200ddc
parentb83f01d0057578ebc1785f858fbfd46cdc210560
c++: libcpp: Support raw strings with newlines in directives [PR55971]

It's not currently possible to use a C++11 raw string containing a newline as
part of the definition of a macro, or in any other preprocessing directive,
such as:

 #define X R"(two
lines)"

 #error R"(this error has
two lines)"

Add support for that by relaxing the conditions under which
_cpp_get_fresh_line() refuses to get a new line. For the case of lexing a raw
string, it's OK to do so as long as there is another line within the current
buffer. The code in cpp_get_fresh_line() was refactored into a new function
get_fresh_line_impl(), so that the new logic is applied only when processing a
raw string and not any other times.

libcpp/ChangeLog:

PR preprocessor/55971
* lex.cc (get_fresh_line_impl): New function refactoring the code
from...
(_cpp_get_fresh_line): ...here.
(lex_raw_string): Use the new version of get_fresh_line_impl() to
support raw strings containing new lines when processing a directive.

gcc/testsuite/ChangeLog:

PR preprocessor/55971
* c-c++-common/raw-string-directive-1.c: New test.
* c-c++-common/raw-string-directive-2.c: New test.

gcc/c-family/ChangeLog:

PR preprocessor/55971
* c-ppoutput.cc (adjust_for_newlines): Update comment.
gcc/c-family/c-ppoutput.cc
gcc/testsuite/c-c++-common/raw-string-directive-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/raw-string-directive-2.c [new file with mode: 0644]
libcpp/lex.cc