[clang] a8b8bd0 - [clang-format] Fix a bug causing BeforeLambdaBody to affect brace initialiser formatting
via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 30 03:12:02 PDT 2020
Author: mydeveloperday
Date: 2020-04-30T11:11:34+01:00
New Revision: a8b8bd0f8d55856858236b36c508eb1d1f4bb6f1
URL: https://github.com/llvm/llvm-project/commit/a8b8bd0f8d55856858236b36c508eb1d1f4bb6f1
DIFF: https://github.com/llvm/llvm-project/commit/a8b8bd0f8d55856858236b36c508eb1d1f4bb6f1.diff
LOG: [clang-format] Fix a bug causing BeforeLambdaBody to affect brace initialiser formatting
Summary: The condition added with the new setting checked whether the character was an l-brace, not specifically a lambda l-brace, when deciding whether it was possible to break before it or not. This caused the l-brace of some initialiser lists to break onto the next line with the first argument of the initialiser list when the setting was enabled.
Reviewed By: MyDeveloperDay, Wawha
Patch By: duncan-llvm
Subscribers: cfe-commits
Tags: #clang, #clang-format
Differential Revision: https://reviews.llvm.org/D79022
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 439fd0f4d863..7623c8344a32 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3938,7 +3938,7 @@ bool TokenAnnotator::canBreakBefore(const AnnotatedLine &Line,
Right.isMemberAccess() ||
Right.isOneOf(TT_TrailingReturnArrow, TT_LambdaArrow, tok::lessless,
tok::colon, tok::l_square, tok::at) ||
- (Style.BraceWrapping.BeforeLambdaBody && Right.is(tok::l_brace)) ||
+ (Style.BraceWrapping.BeforeLambdaBody && Right.is(TT_LambdaLBrace)) ||
(Left.is(tok::r_paren) &&
Right.isOneOf(tok::identifier, tok::kw_const)) ||
(Left.is(tok::l_paren) && !Right.is(tok::r_paren)) ||
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index ace4113393f0..2892972b8175 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -8395,6 +8395,17 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
format("vector<int> SomeVector = { // aaa\n"
" 1, 2, };"));
+ // C++11 brace initializer list l-braces should not be treated any
diff erently
+ // when breaking before lambda bodies is enabled
+ FormatStyle BreakBeforeLambdaBody = getLLVMStyle();
+ BreakBeforeLambdaBody.BreakBeforeBraces = FormatStyle::BS_Custom;
+ BreakBeforeLambdaBody.BraceWrapping.BeforeLambdaBody = true;
+ BreakBeforeLambdaBody.AlwaysBreakBeforeMultilineStrings = true;
+ verifyFormat(
+ "std::runtime_error{\n"
+ " \"Long string which will force a break onto the next line...\"};",
+ BreakBeforeLambdaBody);
+
FormatStyle ExtraSpaces = getLLVMStyle();
ExtraSpaces.Cpp11BracedListStyle = false;
ExtraSpaces.ColumnLimit = 75;
More information about the cfe-commits
mailing list