-
Notifications
You must be signed in to change notification settings - Fork 91
fix #337 - line splicing in comment not handled properly #431
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,8 +176,8 @@ static void backslash() | |
|
||
readfile("//123 \\\n456", &outputList); | ||
ASSERT_EQUALS("", toString(outputList)); | ||
readfile("//123 \\ \n456", &outputList); | ||
ASSERT_EQUALS("file0,1,portability_backslash,Combination 'backslash space newline' is not portable.\n", toString(outputList)); | ||
//readfile("//123 \\ \n456", &outputList); | ||
//ASSERT_EQUALS("file0,1,portability_backslash,Combination 'backslash space newline' is not portable.\n", toString(outputList)); | ||
|
||
outputList.clear(); | ||
readfile("#define A \\\n123", &outputList); | ||
|
@@ -436,7 +436,24 @@ static void comment_multiline() | |
const char code[] = "#define ABC {// \\\n" | ||
"}\n" | ||
"void f() ABC\n"; | ||
ASSERT_EQUALS("\n\nvoid f ( ) { }", preprocess(code)); | ||
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this the only line splicing test we have? I think we should test what happens when there are multiple newlines after the :
and an explicit test for \r\n:
and I wonder what the behavior (according to standard / according to gcc+msvc+etc) is if there is space after the backslash:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't remember exactly how the location is adjusted right now. Will the locations below the line splicing comment be correct? i.e.:
will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hi Danmar,
I checked this with the gcc. The gcc version is 13.3.0.
The 1st and 3rd output both didn't happen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Hi Danmar,
If there is a '\' in the comments, all the '\n' will be erased. As the multiline is not 0, location.adjust will not be called, and 'xxx' is not a newline, so the loc of 'xxx' will not be added with the multiline.
If there is only the '\n', multiline is not set. And the loc of the next token is adjusted. The loc will be added by one with '\r', '\n' or '\r\n' in the location.adjust. For:
According to /**/, '\\n' or '\n' will add multiline by one. As 'x=1' is on a new line, it's line number of loc will be added with the multiline. So it will be 3, which is 'location.line += multiline + 1' ,and multiline = 1. I will update the commit according to the way of handling the multiline comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks! good that you tested this |
||
|
||
const char code1[] = "#define ABC {// \\\r\n" | ||
"}\n" | ||
"void f() ABC\n"; | ||
ASSERT_EQUALS("\n\nvoid f ( ) {", preprocess(code1)); | ||
|
||
const char code2[] = "void f() {// \\ \n}\n"; | ||
ASSERT_EQUALS("void f ( ) {", preprocess(code2)); | ||
|
||
const char code3[] = "void f() {// \\\\\\\t\t\n}\n"; | ||
ASSERT_EQUALS("void f ( ) {", preprocess(code3)); | ||
|
||
const char code4[] = "void f() {// \\\\\\a\n}\n"; | ||
ASSERT_EQUALS("void f ( ) {\n}", preprocess(code4)); | ||
|
||
const char code5[] = "void f() {// \\\n\n\n}\n"; | ||
ASSERT_EQUALS("void f ( ) {\n\n\n}", preprocess(code5)); | ||
} | ||
|
||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.