[PATCH] D79020: [clang-format] Correct the AfterControlStatement configuration option output style

2020-04-28 Thread Duncan Barber via Phabricator via cfe-commits
duncan-llvm added a comment.

Based on the New Contributors 
 section I 
understand I should be asking someone to commit this (and D79022 
) on my behalf. @MyDeveloperDay would you be 
able to do that for me or suggest someone else I can ask?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D79020/new/

https://reviews.llvm.org/D79020



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79022: [clang-format] Fix a bug causing BeforeLambdaBody to affect brace initialiser formatting

2020-04-28 Thread Duncan Barber via Phabricator via cfe-commits
duncan-llvm created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
duncan-llvm added reviewers: MyDeveloperDay, Wawha.
duncan-llvm added a project: clang-format.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79022

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
@@ -8381,6 +8381,17 @@
 format("vector SomeVector = { // aaa\n"
"1, 2, };"));
 
+  // C++11 brace initializer list l-braces should not be treated any 
differently
+  // 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;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3928,7 +3928,7 @@
  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)) ||


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -8381,6 +8381,17 @@
 format("vector SomeVector = { // aaa\n"
"1, 2, };"));
 
+  // C++11 brace initializer list l-braces should not be treated any differently
+  // 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;
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3928,7 +3928,7 @@
  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)) ||
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D79020: [clang-format] Correct the AfterControlStatement configuration option output style

2020-04-28 Thread Duncan Barber via Phabricator via cfe-commits
duncan-llvm created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
duncan-llvm edited the summary of this revision.
duncan-llvm added a reviewer: MyDeveloperDay.
duncan-llvm added a project: clang-format.

Due to the order in which the enum cases were defined the old options which 
were retained for backwards compatibility were being preferred over the new 
options when printing with the --dump-config option.

I wasn't sure where this stood in regard to tests - I couldn't find anything 
testing the enum/string conversions in this direction, so if I've missed 
something please point me in the right direction and I'll add something.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D79020

Files:
  clang/lib/Format/Format.cpp


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -195,11 +195,13 @@
   static void
   enumeration(IO ,
   FormatStyle::BraceWrappingAfterControlStatementStyle ) {
-IO.enumCase(Value, "false", FormatStyle::BWACS_Never);
-IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
 IO.enumCase(Value, "Never", FormatStyle::BWACS_Never);
 IO.enumCase(Value, "MultiLine", FormatStyle::BWACS_MultiLine);
 IO.enumCase(Value, "Always", FormatStyle::BWACS_Always);
+
+// For backward compatibility.
+IO.enumCase(Value, "false", FormatStyle::BWACS_Never);
+IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
   }
 };
 


Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -195,11 +195,13 @@
   static void
   enumeration(IO ,
   FormatStyle::BraceWrappingAfterControlStatementStyle ) {
-IO.enumCase(Value, "false", FormatStyle::BWACS_Never);
-IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
 IO.enumCase(Value, "Never", FormatStyle::BWACS_Never);
 IO.enumCase(Value, "MultiLine", FormatStyle::BWACS_MultiLine);
 IO.enumCase(Value, "Always", FormatStyle::BWACS_Always);
+
+// For backward compatibility.
+IO.enumCase(Value, "false", FormatStyle::BWACS_Never);
+IO.enumCase(Value, "true", FormatStyle::BWACS_Always);
   }
 };
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits