[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-14 Thread Hans Wennborg via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL334692: [clang-format] Add SpaceBeforeCpp11BracedList 
option. (authored by hans, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D46024?vs=150984&id=151308#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D46024

Files:
  cfe/trunk/docs/ClangFormatStyleOptions.rst
  cfe/trunk/include/clang/Format/Format.h
  cfe/trunk/lib/Format/Format.cpp
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/unittests/Format/FormatTest.cpp

Index: cfe/trunk/include/clang/Format/Format.h
===
--- cfe/trunk/include/clang/Format/Format.h
+++ cfe/trunk/include/clang/Format/Format.h
@@ -1495,6 +1495,17 @@
   /// \endcode
   bool SpaceBeforeAssignmentOperators;
 
+  /// If ``true``, a space will be inserted before a C++11 braced list
+  /// used to initialize an object (after the preceding identifier or type).
+  /// \code
+  ///true:  false:
+  ///Foo foo { bar };   vs. Foo foo{ bar };
+  ///Foo {};Foo{};
+  ///vector { 1, 2, 3 };   vector{ 1, 2, 3 };
+  ///new int[3] { 1, 2, 3 };new int[3]{ 1, 2, 3 };
+  /// \endcode
+  bool SpaceBeforeCpp11BracedList;
+
   /// If ``false``, spaces will be removed before constructor initializer
   /// colon.
   /// \code
@@ -1738,6 +1749,7 @@
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
+   SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
SpaceBeforeCtorInitializerColon ==
R.SpaceBeforeCtorInitializerColon &&
SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -2548,6 +2548,9 @@
   if (Style.isCpp()) {
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
+if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
+!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
+  return true;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 if (Right.is(tok::period) &&
Index: cfe/trunk/lib/Format/Format.cpp
===
--- cfe/trunk/lib/Format/Format.cpp
+++ cfe/trunk/lib/Format/Format.cpp
@@ -449,6 +449,8 @@
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceBeforeAssignmentOperators",
Style.SpaceBeforeAssignmentOperators);
+IO.mapOptional("SpaceBeforeCpp11BracedList",
+   Style.SpaceBeforeCpp11BracedList);
 IO.mapOptional("SpaceBeforeCtorInitializerColon",
Style.SpaceBeforeCtorInitializerColon);
 IO.mapOptional("SpaceBeforeInheritanceColon",
@@ -697,6 +699,7 @@
   LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
   LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
+  LLVMStyle.SpaceBeforeCpp11BracedList = false;
   LLVMStyle.SpacesInAngles = false;
 
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
@@ -892,6 +895,7 @@
   Style.ObjCBlockIndentWidth = 4;
   Style.ObjCSpaceAfterProperty = true;
   Style.PointerAlignment = FormatStyle::PAS_Left;
+  Style.SpaceBeforeCpp11BracedList = true;
   return Style;
 }
 
Index: cfe/trunk/unittests/Format/FormatTest.cpp
===
--- cfe/trunk/unittests/Format/FormatTest.cpp
+++ cfe/trunk/unittests/Format/FormatTest.cpp
@@ -7019,6 +7019,11 @@
"  { \"c\", 2 }\n"
"};",
ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();
+  SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
+  verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
+  verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -10622,6 +10627,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
Index: cfe/trunk/docs/ClangFormatStyleOptions.rst
===
--- cfe/trunk/docs/ClangFormatStyleOptions.rst
+++ 

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-13 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

I'll need someone to commit. Thanks!


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-13 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

Ross, do you have commit access or do you need someone to commit this for you?


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-12 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling updated this revision to Diff 150984.
rkirsling added a comment.

Addressed feedback—thank you for the review!


Repository:
  rC Clang

https://reviews.llvm.org/D46024

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -7019,6 +7019,11 @@
"  { \"c\", 2 }\n"
"};",
ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();
+  SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
+  verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
+  verifyFormat("f({}, {{}, {}}, MyMap[{k, v}]);", SpaceBeforeBrace);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -10622,6 +10627,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2548,6 +2548,9 @@
   if (Style.isCpp()) {
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
+if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
+!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
+  return true;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 if (Right.is(tok::period) &&
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -449,6 +449,8 @@
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceBeforeAssignmentOperators",
Style.SpaceBeforeAssignmentOperators);
+IO.mapOptional("SpaceBeforeCpp11BracedList",
+   Style.SpaceBeforeCpp11BracedList);
 IO.mapOptional("SpaceBeforeCtorInitializerColon",
Style.SpaceBeforeCtorInitializerColon);
 IO.mapOptional("SpaceBeforeInheritanceColon",
@@ -697,6 +699,7 @@
   LLVMStyle.SpaceBeforeParens = FormatStyle::SBPO_ControlStatements;
   LLVMStyle.SpaceBeforeRangeBasedForLoopColon = true;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
+  LLVMStyle.SpaceBeforeCpp11BracedList = false;
   LLVMStyle.SpacesInAngles = false;
 
   LLVMStyle.PenaltyBreakAssignment = prec::Assignment;
@@ -892,6 +895,7 @@
   Style.ObjCBlockIndentWidth = 4;
   Style.ObjCSpaceAfterProperty = true;
   Style.PointerAlignment = FormatStyle::PAS_Left;
+  Style.SpaceBeforeCpp11BracedList = true;
   return Style;
 }
 
Index: include/clang/Format/Format.h
===
--- include/clang/Format/Format.h
+++ include/clang/Format/Format.h
@@ -1495,6 +1495,17 @@
   /// \endcode
   bool SpaceBeforeAssignmentOperators;
 
+  /// If ``true``, a space will be inserted before a C++11 braced list
+  /// used to initialize an object (after the preceding identifier or type).
+  /// \code
+  ///true:  false:
+  ///Foo foo { bar };   vs. Foo foo{ bar };
+  ///Foo {};Foo{};
+  ///vector { 1, 2, 3 };   vector{ 1, 2, 3 };
+  ///new int[3] { 1, 2, 3 };new int[3]{ 1, 2, 3 };
+  /// \endcode
+  bool SpaceBeforeCpp11BracedList;
+
   /// If ``false``, spaces will be removed before constructor initializer
   /// colon.
   /// \code
@@ -1738,6 +1749,7 @@
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
+   SpaceBeforeCpp11BracedList == R.SpaceBeforeCpp11BracedList &&
SpaceBeforeCtorInitializerColon ==
R.SpaceBeforeCtorInitializerColon &&
SpaceBeforeInheritanceColon == R.SpaceBeforeInheritanceColon &&
Index: docs/ClangFormatStyleOptions.rst
===
--- docs/ClangFormatStyleOptions.rst
+++ docs/ClangFormatStyleOptions.rst
@@ -1791,6 +1791,18 @@
  int a = 5; vs. int a=5;
  a += 42a+=42;
 
+**SpaceBeforeCpp11BracedList** (``bool``)
+  If ``true``, a space will be inserted before a C++11 braced list
+  used to initialize an object (after the preceding identifier or type).
+
+  .. code-block:: c++
+
+ t

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-12 Thread Manuel Klimek via Phabricator via cfe-commits
klimek accepted this revision.
klimek added a comment.

In https://reviews.llvm.org/D46024#1129350, @hans wrote:

> In https://reviews.llvm.org/D46024#1121242, @rkirsling wrote:
>
> > FWIW, please note that this space-before-brace style is not specific to 
> > WebKit; CppCoreGuidelines exhibits it as well:
> >  
> > http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax
>
>
> This and WebKit's style seem like compelling arguments to support this option.
>
> klimek, djasper: Do you have any objections against landing this?


Agreed.
Generally LG minus that I'd significantly reduce the number of test cases :)




Comment at: unittests/Format/FormatTest.cpp:6980
ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();

There are super many redundant test cases here - I don't think we need to test 
that brace init detection works here, again.
I think given the code change we basically need 2 tests:
one where the previous opens a scope, and one where it doesn't.


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-12 Thread Hans Wennborg via Phabricator via cfe-commits
hans added a comment.

In https://reviews.llvm.org/D46024#1121242, @rkirsling wrote:

> FWIW, please note that this space-before-brace style is not specific to 
> WebKit; CppCoreGuidelines exhibits it as well:
>  
> http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax


This and WebKit's style seem like compelling arguments to support this option.

klimek, djasper: Do you have any objections against landing this?


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-04 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In https://reviews.llvm.org/D46024#1121242, @rkirsling wrote:

> FWIW, please note that this space-before-brace style is not specific to 
> WebKit; CppCoreGuidelines exhibits it as well:
>  
> http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax


The main point of clang-format, for me , is to not argue about style. Can we... 
not argue about WebKit's and others' choice? :)


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-06-04 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

FWIW, please note that this space-before-brace style is not specific to WebKit; 
CppCoreGuidelines exhibits it as well:
http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#es23-prefer-the--initializer-syntax


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-31 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling updated this revision to Diff 149395.
rkirsling added a comment.

Resolved another rebase conflict to keep this patch mergeable.


Repository:
  rC Clang

https://reviews.llvm.org/D46024

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6977,6 +6977,67 @@
"  { \"c\", 2 }\n"
"};",
ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();
+  SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
+  verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
+  verifyFormat("vector x {\n"
+   "1,\n"
+   "2,\n"
+   "3,\n"
+   "4,\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector x {{}, {}, {}, {}};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2});", SpaceBeforeBrace);
+  verifyFormat("auto v = Foo {-1};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", SpaceBeforeBrace);
+  verifyFormat("Class::Class : member {1, 2, 3} {}", SpaceBeforeBrace);
+  verifyFormat("new vector {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int[3] {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int {1};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, SomeType {parameter}};", SpaceBeforeBrace);
+  verifyFormat("int count = set {f(), g(), h()}.size();",
+   SpaceBeforeBrace);
+  verifyFormat("new T {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("f(MyMap[{composite, key}]);", SpaceBeforeBrace);
+  verifyFormat("class Class {\n"
+   "  T member = {arg1, arg2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector foo = {::SomeGlobalFunction()};",
+   SpaceBeforeBrace);
+  verifyFormat("const struct A a = {.a = 1, .b = 2};", SpaceBeforeBrace);
+  verifyFormat("const struct A a = {[0] = 1, [1] = 2};", SpaceBeforeBrace);
+  verifyFormat("static_assert(std::is_integral {} + 0, \"\");",
+   SpaceBeforeBrace);
+  verifyFormat("int a = std::is_integral {} + 0;", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("auto i = decltype(x) {};", SpaceBeforeBrace);
+  verifyFormat("std::vector v = {1, 0 /* comment */};",
+   SpaceBeforeBrace);
+  verifyFormat("Node n {1, Node {1000}, //\n"
+   "2};",
+   SpaceBeforeBrace);
+  verifyFormat("Aaaa aaa {\n"
+   "{\n"
+   ",\n"
+   "},\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public D {\n"
+   "  SomeClass SC {2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public A {\n"
+   "  class D : public B {\n"
+   "void f() { int i {2}; }\n"
+   "  };\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("#define A {a, a},", SpaceBeforeBrace);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -10558,6 +10619,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2548,6 +2548,9 @@
   if (Style.isCpp()) {
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
+if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
+!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
+  return true;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 if (Right.is(tok::period) &&
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -428,6 +428,8 @@
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceBeforeAssignmentOperators",
Style.SpaceBeforeAssignmentOperators);
+IO.mapOptional("SpaceBeforeCpp11BracedList",
+   Style.SpaceBeforeCpp11BracedList);
 IO.mapOptional("SpaceBeforeCtorInitializerColon",
Styl

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-24 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

@klimek In our IRC discussion yesterday, I know you expressed disapproval of 
WebKit's choice, but given its reality, am I correct in concluding that this 
can be landed?


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-16 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

If there are no objections to this change, may I request a commit based on the 
approval that @jfb provided?


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-11 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling updated this revision to Diff 146355.
rkirsling added a comment.

Updated patch to resolve conflict and include full diff context.


Repository:
  rC Clang

https://reviews.llvm.org/D46024

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6864,6 +6864,67 @@
   verifyFormat("vector foo = { ::SomeGlobalFunction() };", ExtraSpaces);
   verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces);
   verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();
+  SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
+  verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
+  verifyFormat("vector x {\n"
+   "1,\n"
+   "2,\n"
+   "3,\n"
+   "4,\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector x {{}, {}, {}, {}};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2});", SpaceBeforeBrace);
+  verifyFormat("auto v = Foo {-1};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", SpaceBeforeBrace);
+  verifyFormat("Class::Class : member {1, 2, 3} {}", SpaceBeforeBrace);
+  verifyFormat("new vector {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int[3] {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int {1};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, SomeType {parameter}};", SpaceBeforeBrace);
+  verifyFormat("int count = set {f(), g(), h()}.size();",
+   SpaceBeforeBrace);
+  verifyFormat("new T {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("f(MyMap[{composite, key}]);", SpaceBeforeBrace);
+  verifyFormat("class Class {\n"
+   "  T member = {arg1, arg2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector foo = {::SomeGlobalFunction()};",
+   SpaceBeforeBrace);
+  verifyFormat("const struct A a = {.a = 1, .b = 2};", SpaceBeforeBrace);
+  verifyFormat("const struct A a = {[0] = 1, [1] = 2};", SpaceBeforeBrace);
+  verifyFormat("static_assert(std::is_integral {} + 0, \"\");",
+   SpaceBeforeBrace);
+  verifyFormat("int a = std::is_integral {} + 0;", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("auto i = decltype(x) {};", SpaceBeforeBrace);
+  verifyFormat("std::vector v = {1, 0 /* comment */};",
+   SpaceBeforeBrace);
+  verifyFormat("Node n {1, Node {1000}, //\n"
+   "2};",
+   SpaceBeforeBrace);
+  verifyFormat("Aaaa aaa {\n"
+   "{\n"
+   ",\n"
+   "},\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public D {\n"
+   "  SomeClass SC {2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public A {\n"
+   "  class D : public B {\n"
+   "void f() { int i {2}; }\n"
+   "  };\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("#define A {a, a},", SpaceBeforeBrace);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -10446,6 +10507,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2538,6 +2538,9 @@
   if (Style.isCpp()) {
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
+if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
+!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
+  return true;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 if (Right.is(tok::period) &&
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -413,6 +413,8 @@
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceBeforeAssignmentOperators",
Style.SpaceBeforeAssignmentOperators);
+IO.mapOptional("SpaceBeforeCpp11BracedList",
+  

[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-07 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

Any further commentary? :)


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-05-01 Thread JF Bastien via Phabricator via cfe-commits
jfb accepted this revision.
jfb added a comment.
This revision is now accepted and ready to land.

On the WebKit side this lgtm. Let's leave some time for clang-format folks to 
chime in.


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-30 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

Rule has been published:
https://webkit.org/code-style-guidelines/#spacing-braced-init

Hopefully that suffices for motivation. :)


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-27 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

Guidelines page has been updated (https://trac.webkit.org/changeset/231085), 
though it may take a bit for the website to update.


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-26 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling added a comment.

In https://reviews.llvm.org/D46024#1079390, @klimek wrote:

> Is this written down somewhere? https://webkit.org/code-style-guidelines/ 
> doesn't seem to mention it.


I agree that it really ought to be mentioned there—I'll try to bring that up 
with the original authors of that document.

It is enforced by the style checker (though the rule is not specific to braced 
initialization):
https://github.com/WebKit/webkit/blob/master/Tools/Scripts/webkitpy/style/checkers/cpp.py#L1972-L1978

Statistically speaking, when grepping the Source directory (excluding 
Source/ThirdParty) for *.h and *.cpp files:

- with space (`\w+\s\{.*\};`) has 11544 matches across 2744 files
- without space (`\w+\{.*\};`) has 29 matches across 10 files


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-26 Thread Manuel Klimek via Phabricator via cfe-commits
klimek added a comment.

Is this written down somewhere? https://webkit.org/code-style-guidelines/ 
doesn't seem to mention it.


Repository:
  rC Clang

https://reviews.llvm.org/D46024



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


[PATCH] D46024: [clang-format] Add SpaceBeforeCpp11BracedList option.

2018-04-24 Thread Ross Kirsling via Phabricator via cfe-commits
rkirsling created this revision.
rkirsling added reviewers: djasper, klimek.
Herald added a subscriber: cfe-commits.

WebKit C++ style for object initialization is as follows:

  Foo foo { bar };

Yet using `clang-format -style=webkit` changes this to:

  Foo foo{ bar };

As there is no existing combination of rules that will ensure a space before a 
braced list in this fashion, this patch adds a new SpaceBeforeCpp11BracedList 
rule.


Repository:
  rC Clang

https://reviews.llvm.org/D46024

Files:
  docs/ClangFormatStyleOptions.rst
  include/clang/Format/Format.h
  lib/Format/Format.cpp
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -6864,6 +6864,67 @@
   verifyFormat("vector foo = { ::SomeGlobalFunction() };", ExtraSpaces);
   verifyFormat("const struct A a = { .a = 1, .b = 2 };", ExtraSpaces);
   verifyFormat("const struct A a = { [0] = 1, [1] = 2 };", ExtraSpaces);
+
+  FormatStyle SpaceBeforeBrace = getLLVMStyle();
+  SpaceBeforeBrace.SpaceBeforeCpp11BracedList = true;
+  verifyFormat("vector x {1, 2, 3, 4};", SpaceBeforeBrace);
+  verifyFormat("vector x {\n"
+   "1,\n"
+   "2,\n"
+   "3,\n"
+   "4,\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector x {{}, {}, {}, {}};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2});", SpaceBeforeBrace);
+  verifyFormat("auto v = Foo {-1};", SpaceBeforeBrace);
+  verifyFormat("f({1, 2}, {{2, 3}, {4, 5}}, c, {d});", SpaceBeforeBrace);
+  verifyFormat("Class::Class : member {1, 2, 3} {}", SpaceBeforeBrace);
+  verifyFormat("new vector {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int[3] {1, 2, 3};", SpaceBeforeBrace);
+  verifyFormat("new int {1};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("return {arg1, SomeType {parameter}};", SpaceBeforeBrace);
+  verifyFormat("int count = set {f(), g(), h()}.size();",
+   SpaceBeforeBrace);
+  verifyFormat("new T {arg1, arg2};", SpaceBeforeBrace);
+  verifyFormat("f(MyMap[{composite, key}]);", SpaceBeforeBrace);
+  verifyFormat("class Class {\n"
+   "  T member = {arg1, arg2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("vector foo = {::SomeGlobalFunction()};",
+   SpaceBeforeBrace);
+  verifyFormat("const struct A a = {.a = 1, .b = 2};", SpaceBeforeBrace);
+  verifyFormat("const struct A a = {[0] = 1, [1] = 2};", SpaceBeforeBrace);
+  verifyFormat("static_assert(std::is_integral {} + 0, \"\");",
+   SpaceBeforeBrace);
+  verifyFormat("int a = std::is_integral {} + 0;", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("int foo(int i) { return fo1 {}(i); }", SpaceBeforeBrace);
+  verifyFormat("auto i = decltype(x) {};", SpaceBeforeBrace);
+  verifyFormat("std::vector v = {1, 0 /* comment */};",
+   SpaceBeforeBrace);
+  verifyFormat("Node n {1, Node {1000}, //\n"
+   "2};",
+   SpaceBeforeBrace);
+  verifyFormat("Aaaa aaa {\n"
+   "{\n"
+   ",\n"
+   "},\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public D {\n"
+   "  SomeClass SC {2};\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("class C : public A {\n"
+   "  class D : public B {\n"
+   "void f() { int i {2}; }\n"
+   "  };\n"
+   "};",
+   SpaceBeforeBrace);
+  verifyFormat("#define A {a, a},", SpaceBeforeBrace);
 }
 
 TEST_F(FormatTest, FormatsBracedListsInColumnLayout) {
@@ -10446,6 +10507,7 @@
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
+  CHECK_PARSE_BOOL(SpaceBeforeCpp11BracedList);
   CHECK_PARSE_BOOL(SpaceBeforeCtorInitializerColon);
   CHECK_PARSE_BOOL(SpaceBeforeInheritanceColon);
   CHECK_PARSE_BOOL(SpaceBeforeRangeBasedForLoopColon);
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2522,6 +2522,9 @@
   if (Style.isCpp()) {
 if (Left.is(tok::kw_operator))
   return Right.is(tok::coloncolon);
+if (Right.is(tok::l_brace) && Right.BlockKind == BK_BracedInit &&
+!Left.opensScope() && Style.SpaceBeforeCpp11BracedList)
+  return true;
   } else if (Style.Language == FormatStyle::LK_Proto ||
  Style.Language == FormatStyle::LK_TextProto) {
 if (Right.is(tok::period) &&
Index: lib/Format/Format.cpp
===
--- lib/For