Bug 57620 - Phantom terminator confuses raw string literal parsing.
Summary: Phantom terminator confuses raw string literal parsing.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-14 22:21 UTC by Lawrence Crowl
Modified: 2013-08-13 15:49 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-06-15 00:00:00


Attachments
gcc49-pr57620.patch (1.91 KB, patch)
2013-06-15 15:51 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Lawrence Crowl 2013-06-14 22:21:49 UTC
The first example of C++11 section 2.14.5 paragraph 5 confuses the scanner.

$ cat test.cc
const char *phantom_terminator = R"a(
)\
a"
)a";
$ xg++ -std=c++11 -g -O2 -c test.cc
test.cc:4:3: warning: missing terminating " character [enabled by default]
 )a";
   ^
test.cc:4:1: error: missing terminating " character
 )a";
 ^
test.cc:4:1: error: expected ',' or ';' before ')' token
Comment 1 Paolo Carlini 2013-06-15 00:05:35 UTC
Maybe Jakub can have a look.
Comment 2 Jakub Jelinek 2013-06-15 09:53:54 UTC
There seems to be more issues in the raw string literal lexing.  E.g.
const char *s = R"a??/(x)a??/";
should be I think handled the same as
const char *s = "x";
with -std=c++11 or -std=gnu++11 -trigraphs, but is not.  We only revert the phase 1 and phase 2 transformations in between ( and ), but they should actually be reverted everywhere between the " after R and the final ".
Comment 3 Jakub Jelinek 2013-06-15 15:51:21 UTC
Created attachment 30306 [details]
gcc49-pr57620.patch

So far only very lightly tested patch, passes raw-string* tests (except for raw-string-2.c which contains also trigraph tests that were valid in the earlier raw string paper, but aren't valid in C++11) and this plus a few other tests.
Will still need to adjust raw-string-2.c, and add sufficient test coverage for all the corner cases.
Comment 4 Paolo Carlini 2013-06-15 17:51:16 UTC
Thanks!
Comment 5 Jakub Jelinek 2013-07-21 04:53:04 UTC
Author: jakub
Date: Sun Jul 21 02:28:03 2013
New Revision: 201091

URL: http://gcc.gnu.org/viewcvs?rev=201091&root=gcc&view=rev
Log:
	PR preprocessor/57620
	* lex.c (lex_raw_string): Undo phase1 and phase2 transformations
	between R" and final " rather than only in between R"del( and )del".

	* c-c++-common/raw-string-2.c (s12, u12, U12, L12): Remove.
	(main): Don't test {s,u,U,L}12.
	* c-c++-common/raw-string-13.c: New test.
	* c-c++-common/raw-string-14.c: New test.
	* c-c++-common/raw-string-15.c: New test.
	* c-c++-common/raw-string-16.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/raw-string-13.c
    trunk/gcc/testsuite/c-c++-common/raw-string-14.c
    trunk/gcc/testsuite/c-c++-common/raw-string-15.c
    trunk/gcc/testsuite/c-c++-common/raw-string-16.c
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/c-c++-common/raw-string-2.c
    trunk/libcpp/ChangeLog
    trunk/libcpp/lex.c
Comment 6 Jakub Jelinek 2013-08-13 15:49:03 UTC
*** Bug 52852 has been marked as a duplicate of this bug. ***