MyDeveloperDay created this revision. MyDeveloperDay added reviewers: klimek, owenpan, krasimir, timwoj. MyDeveloperDay added a project: clang-tools-extra. Herald added a project: clang.
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. Repository: rC Clang https://reviews.llvm.org/D67718 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14001,6 +14001,15 @@ 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 Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2580,7 +2580,8 @@ (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 =
Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -14001,6 +14001,15 @@ 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 Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2580,7 +2580,8 @@ (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 =
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits