[PATCH] D93846: [clang-format] PR16518 Add flag to suppress empty line insertion before access modifier
Albertas Vyšniauskas via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Dec 31 12:07:15 PST 2020
thezbyg marked 2 inline comments as done.
thezbyg added a comment.
After some updating, rebuilding and searching for differences in Objective-C++ formatting, I managed to find where the problem with these failing tests is. In **_verifyFormat** function C++ code formatting is tested for stability like this:
EXPECT_EQ(Expected.str(), format(Expected, Style));
EXPECT_EQ(Expected.str(), format(Code, Style));
, but Objective-C++ test, in the same function, looks like this:
EXPECT_EQ(Expected.str(), format(test::messUp(Code), ObjCStyle));
**test::messUp** function removes all newlines and indentation, so test code:
struct foo {
int i;
private:
int j;
}
turns into:
struct foo { int i; private: int j; }
After running **format** on this code, we get incorrect result:
struct foo {
int i;
private:
int j;
}
Running **format** again would produce the correct output:
struct foo {
int i;
private:
int j;
}
So it seems that insertion of empty line fails when access modifier is in the same line as previous tokens. Unmodified clang-format produces the same output. As this behavior is not related to the changes in my patch, should we attempt to fix it here, or a separate bug report would be preferred?
The situation with tests containing comments is similar, because **test::messUp** single line output is formatted into:
struct foo { /* comment */
private:
int i;
int j;
}
which is not the same as:
struct foo {
/* comment */
private:
int i;
int j;
}
In my opinion, Objective-C++ **test::messUp** test incorrectly expects any code collapsed into a single line to format into the same code as formatted original code.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D93846/new/
https://reviews.llvm.org/D93846
More information about the cfe-commits
mailing list