r372249 - [clang-format][PR41899] PointerAlignment: Left leads to useless space in lambda intializer expression
Paul Hoad via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 18 12:11:40 PDT 2019
Author: paulhoad
Date: Wed Sep 18 12:11:40 2019
New Revision: 372249
URL: http://llvm.org/viewvc/llvm-project?rev=372249&view=rev
Log:
[clang-format][PR41899] PointerAlignment: Left leads to useless space in lambda intializer expression
Summary:
https://bugs.llvm.org/show_bug.cgi?id=41899
```auto lambda = [&a = a]() { a = 2; };```
is formatted as
```auto lambda = [& a = a]() { a = 2; };```
With an extra space if PointerAlignment is set to Left
> The space "& a" looks strange when there is no type in the lambda's intializer expression. This can be worked around with by setting "PointerAlignment: Right", but ideally "PointerAlignment: Left" would not add a space in this case.
Reviewers: klimek, owenpan, krasimir, timwoj
Reviewed By: klimek
Subscribers: cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D67718
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=372249&r1=372248&r2=372249&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Sep 18 12:11:40 2019
@@ -2580,7 +2580,8 @@ bool TokenAnnotator::spaceRequiredBetwee
(Style.PointerAlignment != FormatStyle::PAS_Right &&
!Line.IsMultiVariableDeclStmt) &&
Left.Previous &&
- !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon));
+ !Left.Previous->isOneOf(tok::l_paren, tok::coloncolon,
+ tok::l_square));
if (Right.is(tok::star) && Left.is(tok::l_paren))
return false;
const auto SpaceRequiredForArrayInitializerLSquare =
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=372249&r1=372248&r2=372249&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Sep 18 12:11:40 2019
@@ -14074,6 +14074,15 @@ TEST_F(FormatTest, TypenameMacros) {
verifyFormat("STACK_OF(int*)* a;", Macros);
}
+TEST_F(FormatTest, AmbersandInLamda) {
+ // Test case reported in https://bugs.llvm.org/show_bug.cgi?id=41899
+ FormatStyle AlignStyle = getLLVMStyle();
+ AlignStyle.PointerAlignment = FormatStyle::PAS_Left;
+ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
+ AlignStyle.PointerAlignment = FormatStyle::PAS_Right;
+ verifyFormat("auto lambda = [&a = a]() { a = 2; };", AlignStyle);
+}
+
} // end namespace
} // end namespace format
} // end namespace clang
More information about the cfe-commits
mailing list