Bug 57824 - Raw string literals not handled correctly in macro arguments or deferred pragmas
Summary: Raw string literals not handled correctly in macro arguments or deferred pragmas
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: rejects-valid
: 52852 (view as bug list)
Depends on:
Blocks:
 
Reported: 2013-07-04 17:20 UTC by Jakub Jelinek
Modified: 2021-07-27 14:14 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
gcc49-pr57824.patch (825 bytes, patch)
2013-07-04 17:36 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2013-07-04 17:20:57 UTC
#define S(s) s

const char x[] = R"(
abc
)";
const char y[] = S(R"(
abc
)");

void bar ();
void foo ()
{
#pragma omp parallel num_threads(sizeof R"(
abc
)")
  bar ();
}

isn't lexed properly.
Comment 1 Jakub Jelinek 2013-07-04 17:36:22 UTC
Created attachment 30459 [details]
gcc49-pr57824.patch

Untested fix.  Seems to work on these testcases without -save-temps, with -save-temps the line numbers in -lineno dumps are off unfortunately, so some further work is needed.  Tom, any ideas?
Comment 2 Jakub Jelinek 2013-07-10 17:43:54 UTC
Author: jakub
Date: Wed Jul 10 16:52:19 2013
New Revision: 200879

URL: http://gcc.gnu.org/viewcvs?rev=200879&root=gcc&view=rev
Log:
	PR preprocessor/57824
	* lex.c (lex_raw_string): Allow reading new-lines if
	in_deferred_pragma or if parsing_args and there is still
	data in the current buffer.

	* c-c++-common/raw-string-17.c: New test.
	* c-c++-common/gomp/pr57824.c: New test.

Added:
    trunk/gcc/testsuite/c-c++-common/gomp/pr57824.c
    trunk/gcc/testsuite/c-c++-common/raw-string-17.c
Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/libcpp/ChangeLog
    trunk/libcpp/lex.c

Fixed for 4.9+.
Comment 3 Jakub Jelinek 2013-08-13 17:03:34 UTC
*** Bug 52852 has been marked as a duplicate of this bug. ***
Comment 4 Moritz Baumann 2021-07-27 14:14:44 UTC
Raw string literals are still not handled correctly in macros in some cases:

#define myMacro(string) u##string

int square(int num) {
    auto string = myMacro(R"EOF(


        
    )EOF");
    // intentional syntax error
    return num * num
}

(https://godbolt.org/z/qYfax5E8x)

The line number in the compiler error message refers to a line that doesn't even exist. It seems like line breaks in the raw string literal are counted twice.