Fix clang-format's detection of structured bindings.
Correctly determine when [ is part of a structured binding instead of a
lambda.
To be able to reuse the implementation already available, this patch also:
- sets the Previous link of FormatTokens in the UnwrappedLineParser
- moves the isCppStructuredBinding function into FormatToken
Before:
auto const const &&[x, y] { A *i };
After:
auto const const && [x, y]{A * i};
Fixing formatting of the type of the structured binding is still missing.
llvm-svn: 313742
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 79fa5a7..1ef0cf8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -310,16 +310,6 @@
return false;
}
- bool isCppStructuredBinding(const FormatToken *Tok) {
- if (!Style.isCpp() || !Tok->is(tok::l_square))
- return false;
- do {
- Tok = Tok->getPreviousNonComment();
- } while (Tok && Tok->isOneOf(tok::kw_const, tok::kw_volatile, tok::amp,
- tok::ampamp));
- return Tok && Tok->is(tok::kw_auto);
- }
-
bool parseSquare() {
if (!CurrentToken)
return false;
@@ -354,7 +344,7 @@
unsigned BindingIncrease = 1;
if (Left->is(TT_Unknown)) {
- if (isCppStructuredBinding(Left)) {
+ if (Left->isCppStructuredBinding(Style)) {
Left->Type = TT_StructuredBindingLSquare;
} else if (StartsObjCMethodExpr) {
Left->Type = TT_ObjCMethodExpr;