diff options
| author | Chih-Hung Hsieh <chh@google.com> | 2017-09-27 00:58:45 +0000 |
|---|---|---|
| committer | Chih-Hung Hsieh <chh@google.com> | 2017-09-27 00:58:45 +0000 |
| commit | 30cd3011121f50531d37198c5a5da465e53d502b (patch) | |
| tree | 359389ba340176ebecd36ae576b135e8eef9048a /clang/lib | |
| parent | ed95fce2287472a7df6171fcdcafe854f3218950 (diff) | |
| download | bcm5719-llvm-30cd3011121f50531d37198c5a5da465e53d502b.tar.gz bcm5719-llvm-30cd3011121f50531d37198c5a5da465e53d502b.zip | |
[clang-format] Adjust space around &/&& of structured bindings
Keep space before or after the &/&& tokens, but not both. For example,
auto [x,y] = a;
auto &[xr, yr] = a; // LLVM style
auto& [xr, yr] = a; // google style
Differential Revision:https://reviews.llvm.org/D35743
llvm-svn: 314264
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 1c6f6bba75e..c321eadf354 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -342,10 +342,10 @@ private: bool ColonFound = false; unsigned BindingIncrease = 1; - if (Left->is(TT_Unknown)) { - if (Left->isCppStructuredBinding(Style)) { - Left->Type = TT_StructuredBindingLSquare; - } else if (StartsObjCMethodExpr) { + if (Left->isCppStructuredBinding(Style)) { + Left->Type = TT_StructuredBindingLSquare; + } else if (Left->is(TT_Unknown)) { + if (StartsObjCMethodExpr) { Left->Type = TT_ObjCMethodExpr; } else if (Style.Language == FormatStyle::LK_JavaScript && Parent && Contexts.back().ContextKind == tok::l_brace && @@ -2515,6 +2515,14 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, TT_TemplateOpener)); if ((Left.is(TT_TemplateOpener)) != (Right.is(TT_TemplateCloser))) return Style.SpacesInAngles; + // Space before TT_StructuredBindingLSquare. + if (Right.is(TT_StructuredBindingLSquare)) + return !Left.isOneOf(tok::amp, tok::ampamp) || + Style.PointerAlignment != FormatStyle::PAS_Right; + // Space before & or && following a TT_StructuredBindingLSquare. + if (Right.Next && Right.Next->is(TT_StructuredBindingLSquare) && + Right.isOneOf(tok::amp, tok::ampamp)) + return Style.PointerAlignment != FormatStyle::PAS_Left; if ((Right.is(TT_BinaryOperator) && !Left.is(tok::l_paren)) || (Left.isOneOf(TT_BinaryOperator, TT_ConditionalExpr) && !Right.is(tok::r_paren))) |

