summaryrefslogtreecommitdiffstats
path: root/clang/lib/Format/WhitespaceManager.cpp
diff options
context:
space:
mode:
authorOwen Pan <owenpiano@gmail.com>2019-05-01 18:23:44 +0000
committerOwen Pan <owenpiano@gmail.com>2019-05-01 18:23:44 +0000
commita0df4d37b0f6bccbd0ce0793f229bd8b130eeb8b (patch)
treefdaa8a20491b16b6aa03903ffa1ba868f3753f9a /clang/lib/Format/WhitespaceManager.cpp
parenta8426ac8c2db8f4b589c4f3e635085d5fa7a54f3 (diff)
downloadbcm5719-llvm-a0df4d37b0f6bccbd0ce0793f229bd8b130eeb8b.tar.gz
bcm5719-llvm-a0df4d37b0f6bccbd0ce0793f229bd8b130eeb8b.zip
[clang-format] Fix a bug in AlignConsecutiveDeclarations.
Fixes PR37175 Differential Revision: https://reviews.llvm.org/D61222 llvm-svn: 359711
Diffstat (limited to 'clang/lib/Format/WhitespaceManager.cpp')
-rw-r--r--clang/lib/Format/WhitespaceManager.cpp18
1 files changed, 15 insertions, 3 deletions
diff --git a/clang/lib/Format/WhitespaceManager.cpp b/clang/lib/Format/WhitespaceManager.cpp
index 9f1ea7022f0..5383addd7ee 100644
--- a/clang/lib/Format/WhitespaceManager.cpp
+++ b/clang/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);
}
OpenPOWER on IntegriCloud