cppfront
cppfront copied to clipboard
[BUG] `"//"` `"/*"` inside string literal treated as real comment and doesn't compile
Describe the bug `"//" "/*" symbols inside string literals treated as comment start and break compilation, like shadowing closing } For // it happens inside { block }
To Reproduce https://cpp2.godbolt.org/z/5KEPj196s Uncomment lines marked as error
main: () = {
std::cout << "//123"; //123, ok
//{ std::cout << "//456"; } //error
:()->_ = "//Ok";
//:()->_ = { return "//Error"; }
a:="*/ ok";
{ c:="*/ ok"; }
//b:="/* error even without {} block";
}
//error: (x) = { return "//"; }
Version latest Command lines cppfront/cppfront $1.cpp2 -p clang++-15 -Icppfront/include $1.cpp -std=c++20 -o $1
Expected result
Success compilation and usage of such string literals
Actual result/error
call.cpp2(32,0): error: end of file reached with 1 missing } to match earlier { on line 1
Additional context
I've encountered this inside lambda, when expanding it and changing short syntax to code block. Then discovered "/*" have same issue even without block.
"*/" doesn't seems to have problem.
Reopening as a reminder to handle the raw string literal case too...
Of course, '\\\n' is not a valid string literal.
~~Does this deserve a different issue? See https://cpp2.godbolt.org/z/e7eWbjPjv:~~
_ = $R"(((_ = s.split('\\\n'), 0))$)";
main.cpp2...
main.cpp2(5,35): error: character literal '\\\' is missing its closing '
main.cpp2(5,40): error: character literal '),' is missing its closing '
main.cpp2(5,26): error: unexpected text - expression-list is not terminated by ) (at '=')