summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2017-02-07 21:38:16 +0000
committerDaniel Jasper <djasper@google.com>2017-02-07 21:38:16 +0000
commit697a8ec6cd613bfae2dea98214b6cce60eada8aa (patch)
tree31276fdde5e1dd618b5cf192ded67d1bb6bff374 /clang
parentc2f323ff9bd044222775da081485185394f753d5 (diff)
downloadbcm5719-llvm-697a8ec6cd613bfae2dea98214b6cce60eada8aa.tar.gz
bcm5719-llvm-697a8ec6cd613bfae2dea98214b6cce60eada8aa.zip
clang-format: Fix bad variable declaration detection.
Before: LooooooooooooooooongType variable(nullptr, [](A *a) {}); After: LooooooooooooooooongType variable(nullptr, [](A *a) {}); llvm-svn: 294358
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp6
-rw-r--r--clang/unittests/Format/FormatTest.cpp5
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 940b5cc57e5..726383eda9b 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -1707,7 +1707,7 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
}
}
- // Check whether parameter list can be long to a function declaration.
+ // Check whether parameter list can belong to a function declaration.
if (!Next || !Next->is(tok::l_paren) || !Next->MatchingParen)
return false;
// If the lines ends with "{", this is likely an function definition.
@@ -1721,6 +1721,10 @@ static bool isFunctionDeclarationName(const FormatToken &Current,
return true;
for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen;
Tok = Tok->Next) {
+ if (Tok->is(tok::l_paren) && Tok->MatchingParen) {
+ Tok = Tok->MatchingParen;
+ continue;
+ }
if (Tok->is(tok::kw_const) || Tok->isSimpleTypeSpecifier() ||
Tok->isOneOf(TT_PointerOrReference, TT_StartOfName, tok::ellipsis))
return true;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 8f531af7054..47124723723 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -6934,6 +6934,11 @@ TEST_F(FormatTest, BreaksLongVariableDeclarations) {
" LoooooooooooooooooooooooooooooooooooooooongVariable({});");
verifyFormat("LoooooooooooooooooooooooooooooooooooooooongType\n"
" LoooooooooooooooooooooooooooooooooooooongVariable([A a]);");
+
+ // Lambdas should not confuse the variable declaration heuristic.
+ verifyFormat("LooooooooooooooooongType\n"
+ " variable(nullptr, [](A *a) {});",
+ getLLVMStyleWithColumns(40));
}
TEST_F(FormatTest, BreaksLongDeclarations) {
OpenPOWER on IntegriCloud