diff options
author | Mitchell Balan <mitchell@stellarscience.com> | 2019-11-14 13:18:34 -0500 |
---|---|---|
committer | Mitchell Balan <mitchell@stellarscience.com> | 2019-11-14 13:24:50 -0500 |
commit | 4ee70e00b509fe26bac4196df76dc7c6153f1206 (patch) | |
tree | 29ea32a22c8842b26ad0288c0f873f62783bf190 | |
parent | 5fe3f00ae2753d84ad2f9ca7c5a2b56c34344dfb (diff) | |
download | bcm5719-llvm-4ee70e00b509fe26bac4196df76dc7c6153f1206.tar.gz bcm5719-llvm-4ee70e00b509fe26bac4196df76dc7c6153f1206.zip |
[clang-format] Fixed edge-case with SpacesInSquareBrackets with trailing bare "&" lambda capture.
Summary:
Lambda captures allow for a lone `&` capture, so `&]` needs to be properly handled.
`int foo = [& ]() {}` is fixed to give `int foo = [ & ]() {}`
Reviewers: MyDeveloperDay
Reviewed by: MyDeveloperDay
Subscribers: cfe-commits
Tags: #clang, #clang-format
Differential Revision: https://reviews.llvm.org/D70249
-rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 10 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 8 insertions, 3 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index d3c9dd56f97..c5ed49e9a40 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2996,14 +2996,18 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, return true; } if (Left.is(TT_UnaryOperator)) { - // The alternative operators for ~ and ! are "compl" and "not". - // If they are used instead, we do not want to combine them with - // the token to the right, unless that is a left paren. if (!Right.is(tok::l_paren)) { + // The alternative operators for ~ and ! are "compl" and "not". + // If they are used instead, we do not want to combine them with + // the token to the right, unless that is a left paren. if (Left.is(tok::exclaim) && Left.TokenText == "not") return true; if (Left.is(tok::tilde) && Left.TokenText == "compl") return true; + // Lambda captures allow for a lone &, so "&]" needs to be properly + // handled. + if (Left.is(tok::amp) && Right.is(tok::r_square)) + return Style.SpacesInSquareBrackets; } return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) || Right.is(TT_BinaryOperator); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 01154e2c2f4..b8a73621c77 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -10638,6 +10638,7 @@ TEST_F(FormatTest, ConfigurableSpacesInSquareBrackets) { verifyFormat("return [ i, args... ] {};", Spaces); verifyFormat("int foo = [ &bar ]() {};", Spaces); verifyFormat("int foo = [ = ]() {};", Spaces); + verifyFormat("int foo = [ & ]() {};", Spaces); verifyFormat("int foo = [ =, &bar ]() {};", Spaces); verifyFormat("int foo = [ &bar, = ]() {};", Spaces); } |