mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-01 01:31:26 +00:00
[clang-format] PR50326 AlignAfterOpenBracket AlwaysBreak does not keep to the ColumnLimit
https://bugs.llvm.org/show_bug.cgi?id=50326 {D93626} caused a regression in terms of formatting a function ptr, incorrectly thinking it was a C-Style cast. This cased a formatter regression between clang-format-11 and clang-format-12 ``` void bar() { size_t foo = function(Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong); size_t foo = function( Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, BarrrrrrrrrrrrLong, FoooooooooLooooong); size_t foo = (*(function))(Foooo, Barrrrr, Foooo, FoooooooooLooooong); size_t foo = (*( function))(Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, BarrrrrrrrrrrrLong, FoooooooooLooooong); } ``` became ``` void bar() { size_t foo1 = function(Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong); size_t foo2 = function( Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, BarrrrrrrrrrrrLong, FoooooooooLooooong); size_t foo3 = (*(function))(Foooo, Barrrrr, Foooo, FoooooooooLooooong); size_t foo4 = (*( function))(Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, BarrrrrrrrrrrrLong, FoooooooooLooooong); } ``` This fixes this issue by simplify the clause to be specific about what is wanted rather than what is not. Reviewed By: curdeius, HazardyKnusperkeks Differential Revision: https://reviews.llvm.org/D102392
This commit is contained in:
parent
6418bab6f8
commit
eae445f65d
@ -1907,12 +1907,12 @@ private:
|
||||
if (Tok.Next->isOneOf(tok::identifier, tok::kw_this))
|
||||
return true;
|
||||
|
||||
if (Tok.Next->is(tok::l_paren) &&
|
||||
!(Tok.Previous && Tok.Previous->is(tok::identifier) &&
|
||||
Tok.Previous->Previous &&
|
||||
Tok.Previous->Previous->isOneOf(tok::arrowstar, tok::arrow,
|
||||
tok::star)))
|
||||
return true;
|
||||
// Look for a cast `( x ) (`.
|
||||
if (Tok.Next->is(tok::l_paren) && Tok.Previous && Tok.Previous->Previous) {
|
||||
if (Tok.Previous->is(tok::identifier) &&
|
||||
Tok.Previous->Previous->is(tok::l_paren))
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!Tok.Next->Next)
|
||||
return false;
|
||||
|
@ -13298,6 +13298,17 @@ TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
|
||||
verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
|
||||
Spaces.ColumnLimit = 80;
|
||||
Spaces.IndentWidth = 4;
|
||||
Spaces.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
|
||||
verifyFormat("void foo( ) {\n"
|
||||
" size_t foo = (*(function))(\n"
|
||||
" Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
|
||||
"BarrrrrrrrrrrrLong,\n"
|
||||
" FoooooooooLooooong);\n"
|
||||
"}",
|
||||
Spaces);
|
||||
Spaces.SpaceAfterCStyleCast = false;
|
||||
verifyFormat("size_t idx = (size_t)(ptr - ((char *)file));", Spaces);
|
||||
verifyFormat("size_t idx = (size_t)a;", Spaces);
|
||||
@ -13305,6 +13316,15 @@ TEST_F(FormatTest, ConfigurableSpacesInParentheses) {
|
||||
verifyFormat("size_t idx = (a->*foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (a->foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (*foo)(a - 1);", Spaces);
|
||||
verifyFormat("size_t idx = (*(foo))(a - 1);", Spaces);
|
||||
|
||||
verifyFormat("void foo( ) {\n"
|
||||
" size_t foo = (*(function))(\n"
|
||||
" Foooo, Barrrrr, Foooo, Barrrr, FoooooooooLooooong, "
|
||||
"BarrrrrrrrrrrrLong,\n"
|
||||
" FoooooooooLooooong);\n"
|
||||
"}",
|
||||
Spaces);
|
||||
}
|
||||
|
||||
TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) {
|
||||
|
Loading…
Reference in New Issue
Block a user