Skip to content

[BUG] '(' (and { ) on 2nd and further line of R string literal causes parse error. #1425

@tattwamasi

Description

@tattwamasi

Describe the bug

When using R string literals for usage documentation and other longer things I found an odd parse issue.
If you use an open parenthesis inside the R string, it should work fine, but it instead causes a parse error if it is on the 2nd or subsequent line of the literal, but only if the literal is being defined at file scope.

To Reproduce
Sample code:
https://godbolt.org/z/qqTq6qzGM

// note BUG: a () in a R string is messing up cppfront parsing, saying:
//    error: closing } does not match a prior {

raw_str_multi_filescope : std::string = R"test(this is raw string literal (hi 1st line paren!)

that has (parens inside) and can last for multiple

lines)test";

main : () = {
    raw_str_multi : std::string = R"test(this is raw string literal (hi 1st line paren!)

that has (parens inside) and can last for multiple

lines)test";
    std::cout << raw_str_multi << std::endl;
    std::cout << raw_str_multi_filescope << std::endl;
}

Compile this as usual (I used the raw string regression test in the project as an initial example). Note the two raw_str_multi* values are exactly the same...
You'll see the compile error. Now remove the open paren before the word 'parens' on the 2nd line of text in the file scope version. Now it will compile and work as expected.

Note, I discovered this with the parenthesis but it looks like the same thing happens with an open or close bracket (but not close paren).
I thought it may be related to issues #442 & #841, but seems like it is a parsing issue tied to scope that may have just not been handled at file scope.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions