diff options
author | Owen Pan <owenpiano@gmail.com> | 2019-05-01 18:23:44 +0000 |
---|---|---|
committer | Owen Pan <owenpiano@gmail.com> | 2019-05-01 18:23:44 +0000 |
commit | c93a7477d59bf70daf83a5d8c32c65dcc9590388 (patch) | |
tree | 61bb2864a84102dececb6dfdd38a027ecbb3b5ea /lib/Format/WhitespaceManager.cpp | |
parent | faa9d11b755b3e108b0bb2811f821fe3b6da8499 (diff) |
[clang-format] Fix a bug in AlignConsecutiveDeclarations.
Fixes PR37175
Differential Revision: https://reviews.llvm.org/D61222
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@359711 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/WhitespaceManager.cpp')
-rw-r--r-- | lib/Format/WhitespaceManager.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/Format/WhitespaceManager.cpp b/lib/Format/WhitespaceManager.cpp index 9f1ea7022f..5383addd7e 100644 --- a/lib/Format/WhitespaceManager.cpp +++ b/lib/Format/WhitespaceManager.cpp @@ -463,9 +463,21 @@ void WhitespaceManager::alignConsecutiveDeclarations() { [](Change const &C) { // tok::kw_operator is necessary for aligning operator overload // definitions. - return C.Tok->is(TT_StartOfName) || - C.Tok->is(TT_FunctionDeclarationName) || - C.Tok->is(tok::kw_operator); + if (C.Tok->isOneOf(TT_FunctionDeclarationName, tok::kw_operator)) + return true; + if (C.Tok->isNot(TT_StartOfName)) + return false; + // Check if there is a subsequent name that starts the same declaration. + for (FormatToken *Next = C.Tok->Next; Next; Next = Next->Next) { + if (Next->is(tok::comment)) + continue; + if (!Next->Tok.getIdentifierInfo()) + break; + if (Next->isOneOf(TT_StartOfName, TT_FunctionDeclarationName, + tok::kw_operator)) + return false; + } + return true; }, Changes, /*StartAt=*/0); } |