diff options
author | Manuel Klimek <klimek@google.com> | 2018-04-11 14:51:54 +0000 |
---|---|---|
committer | Manuel Klimek <klimek@google.com> | 2018-04-11 14:51:54 +0000 |
commit | d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715 (patch) | |
tree | 35c44122039db2a31f30e18b63d877664c03f1c7 /clang/lib | |
parent | 9381ae9791d57dd09fa10c22d52a17ca2bbcd4b2 (diff) | |
download | bcm5719-llvm-d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715.tar.gz bcm5719-llvm-d0f3fe5563a96d0db9e7fc27c54a3a0b1083c715.zip |
Fix bugs around handling C++11 attributes.
Previously, we would format:
int a() { ... }
[[unused]] int b() { ... }
as...
int a() {} [[unused] int b() {}
Now we correctly format each on its own line.
Similarly, we would detect:
[[unused]] int b() { return 42; }
As a lambda and leave it on a single line, even if that was disallowed
by the format style.
llvm-svn: 329816
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Format/UnwrappedLineParser.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index be7e2bbabac..b61ffb21d84 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -449,12 +449,19 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { (Style.isCpp() && NextTok->is(tok::l_paren)) || NextTok->isOneOf(tok::comma, tok::period, tok::colon, tok::r_paren, tok::r_square, tok::l_brace, - tok::l_square, tok::ellipsis) || + tok::ellipsis) || (NextTok->is(tok::identifier) && !PrevTok->isOneOf(tok::semi, tok::r_brace, tok::l_brace)) || (NextTok->is(tok::semi) && (!ExpectClassBody || LBraceStack.size() != 1)) || (NextTok->isBinaryOperator() && !NextIsObjCMethod); + if (NextTok->is(tok::l_square)) { + // We can have an array subscript after a braced init + // list, but C++11 attributes are expected after blocks. + NextTok = Tokens->getNextToken(); + ++ReadTokens; + ProbablyBracedList = NextTok->isNot(tok::l_square); + } } if (ProbablyBracedList) { Tok->BlockKind = BK_BracedInit; @@ -1406,13 +1413,16 @@ bool UnwrappedLineParser::tryToParseLambdaIntroducer() { const FormatToken *Previous = FormatTok->Previous; if (Previous && (Previous->isOneOf(tok::identifier, tok::kw_operator, tok::kw_new, - tok::kw_delete) || + tok::kw_delete, tok::l_square) || FormatTok->isCppStructuredBinding(Style) || Previous->closesScope() || Previous->isSimpleTypeSpecifier())) { nextToken(); return false; } nextToken(); + if (FormatTok->is(tok::l_square)) { + return false; + } parseSquare(/*LambdaIntroducer=*/true); return true; } |