[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets

2017-09-15 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Thank you!


https://reviews.llvm.org/D37846



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


[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternBlock

2017-09-15 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

I would be grateful, thank you!


https://reviews.llvm.org/D37845



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


[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets

2017-09-15 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 115369.
PriMee added a comment.

Done :)


https://reviews.llvm.org/D37846

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp

Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -20,11 +20,26 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
+void d(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void d(int  /*i*/[]) {}{{$}}
+
+void e(int i[1]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void e(int  /*i*/[1]) {}{{$}}
+
+void f(void (*fn)()) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:15: warning: parameter 'fn' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void f(void (* /*fn*/)()) {}{{$}}
+
 // Unchanged cases
 // ===
 void f(int i); // Don't remove stuff in declarations
 void g(int i = 1);
-void h(int i) { (void)i; } // Don't remove used parameters
+void h(int i[]);
+void s(int i[1]);
+void u(void (*fn)());
+void w(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
 static bool static_var = useLambda([] (int a) { return a; });
@@ -59,6 +74,18 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionF()
 
+static void staticFunctionG(int i[]);
+// CHECK-FIXES: {{^}}static void staticFunctionG();
+static void staticFunctionG(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionG()
+
+static void staticFunctionH(void (*fn)());
+// CHECK-FIXES: {{^}}static void staticFunctionH();
+static void staticFunctionH(void (*fn)()) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:36: warning
+// CHECK-FIXES: {{^}}static void staticFunctionH()
+
 static void someCallSites() {
   staticFunctionA(1);
 // CHECK-FIXES: staticFunctionA();
@@ -74,6 +101,12 @@
 // CHECK-FIXES: staticFunctionF();
   staticFunctionF();
 // CHECK-FIXES: staticFunctionF();
+  int t[] = {1};
+  staticFunctionG(t);
+// CHECK-FIXES: staticFunctionG();
+  void func();
+  staticFunctionH();
+// CHECK-FIXES: staticFunctionH();  
 }
 
 /*
@@ -109,6 +142,12 @@
   static void g(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void g(int  /*i*/ = 1) {}
+  static void h(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void h(int  /*i*/[]) {}
+  static void s(void (*fn)()) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning
+// CHECK-FIXES: static void s(void (* /*fn*/)()) {}
 };
 
 namespace {
@@ -125,6 +164,12 @@
   void s(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void s(int  /*i*/ = 1) {}
+  void u(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void u(int  /*i*/[]) {}
+  void w(void (*fn)()) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning
+// CHECK-FIXES: void w(void (* /*fn*/)()) {}
 };
 
 void C::f(int i) {}
@@ -142,7 +187,9 @@
 // CHECK-FIXES: c.g();
 
   useFunction(::h);
-  useFunction(::s);;
+  useFunction(::s);
+  useFunction(::u);
+  useFunction(::w);
 }
 
 class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,8 +138,7 @@
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(),
- Param->DeclaratorDecl::getSourceRange().getEnd());
+SourceRange RemovalRange(Param->getLocation());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format will
 // clean this up afterwards.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternBlock

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 115240.
PriMee added a comment.

Thank you for noticing! Done.


https://reviews.llvm.org/D37845

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1704,7 +1704,42 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) {
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {}");
+  verifyFormat("extern \"C\" {\n"
+   "int foo();\n"
+   "}");
+  verifyFormat("extern \"C\" int foo() {}");
+  verifyFormat("extern \"C\" int foo();");
+  verifyFormat("extern \"C\" int foo() {\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("extern \"C\" int foo() {}", Style);
+  verifyFormat("extern \"C\" int foo();", Style);
+  verifyFormat("extern \"C\" int foo()\n"
+   "{\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}",
+   Style);
+
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.BraceWrapping.SplitEmptyRecord = false;
+  verifyFormat("extern \"C\"\n"
+   "{}",
+   Style);
+  verifyFormat("extern \"C\"\n"
+   "{\n"
+   "  int foo();\n"
+   "}",
+   Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
@@ -9979,6 +10014,7 @@
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterObjCDeclaration);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterStruct);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterUnion);
+  CHECK_PARSE_NESTED_BOOL(BraceWrapping, AfterExternBlock);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeCatch);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, BeforeElse);
   CHECK_PARSE_NESTED_BOOL(BraceWrapping, IndentBraces);
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1039,7 +1039,12 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+if (Style.BraceWrapping.AfterExternBlock) {
+  addUnwrappedLine();
+  parseBlock(/*MustBeDeclaration=*/true);
+} else {
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+}
 addUnwrappedLine();
 return;
   }
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -233,9 +233,10 @@
   if (Tok && Tok->is(tok::kw_typedef))
 Tok = Tok->getNextNonComment();
   if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
-  Keywords.kw_interface))
+  tok::kw_extern, Keywords.kw_interface))
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
-? tryMergeSimpleBlock(I, E, Limit) : 0;
+   ? tryMergeSimpleBlock(I, E, Limit)
+   : 0;
 }
 
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -420,6 +420,7 @@
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
 IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
+IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
@@ -500,9 +501,9 @@
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {false, false, false, false, false, false, 
+false, false, false, false, false, false, 
+true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   

[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Diff will be updated as soon as possible.




Comment at: clang-tidy/misc/UnusedParametersCheck.cpp:141
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(),
- Param->DeclaratorDecl::getSourceRange().getEnd());
+SourceRange RemovalRange(Param->getLocation(), Param->Decl::getLocation());
 // Note: We always add a space before the '/*' to not accidentally create a

alexfh wrote:
> BTW, can we just remove a single token representing the parameter name? E.g. 
> `SourceRange RemovalRange(Param->getLocation());`.
Yes, you're right :)


Repository:
  rL LLVM

https://reviews.llvm.org/D37846



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


[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternBlock

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 115202.
PriMee added a comment.

Sorry, forgot again...


https://reviews.llvm.org/D37845

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1704,7 +1704,42 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) {
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {}");
+  verifyFormat("extern \"C\" {\n"
+   "int foo();\n"
+   "}");
+  verifyFormat("extern \"C\" int foo() {}");
+  verifyFormat("extern \"C\" int foo();");
+  verifyFormat("extern \"C\" int foo() {\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}");
+
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("extern \"C\" int foo() {}", Style);
+  verifyFormat("extern \"C\" int foo();", Style);
+  verifyFormat("extern \"C\" int foo()\n"
+   "{\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}",
+   Style);
+
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.BraceWrapping.SplitEmptyRecord = false;
+  verifyFormat("extern \"C\"\n"
+   "{}",
+   Style);
+  verifyFormat("extern \"C\"\n"
+   "{\n"
+   "  int foo();\n"
+   "}",
+   Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1039,7 +1039,12 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+if (Style.BraceWrapping.AfterExternBlock) {
+  addUnwrappedLine();
+  parseBlock(/*MustBeDeclaration=*/true);
+} else {
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+}
 addUnwrappedLine();
 return;
   }
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -233,9 +233,10 @@
   if (Tok && Tok->is(tok::kw_typedef))
 Tok = Tok->getNextNonComment();
   if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
-  Keywords.kw_interface))
+  tok::kw_extern, Keywords.kw_interface))
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
-? tryMergeSimpleBlock(I, E, Limit) : 0;
+   ? tryMergeSimpleBlock(I, E, Limit)
+   : 0;
 }
 
 // FIXME: TheLine->Level != 0 might or might not be the right check to do.
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -420,6 +420,7 @@
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
 IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
+IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
@@ -500,9 +501,9 @@
   if (Style.BreakBeforeBraces == FormatStyle::BS_Custom)
 return Style;
   FormatStyle Expanded = Style;
-  Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false, true,
-true,  true};
+  Expanded.BraceWrapping = {false, false, false, false, false, false, 
+false, false, false, false, false, false, 
+true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -515,6 +516,7 @@
 Expanded.BraceWrapping.AfterFunction = true;
 Expanded.BraceWrapping.AfterStruct = true;
 Expanded.BraceWrapping.AfterUnion = true;
+Expanded.BraceWrapping.AfterExternBlock = true;
 Expanded.BraceWrapping.SplitEmptyFunction = true;
 Expanded.BraceWrapping.SplitEmptyRecord = false;
 break;
@@ -531,13 +533,14 @@
  

[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternC

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 115192.
PriMee added a comment.

Done :)


https://reviews.llvm.org/D37845

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1704,7 +1704,42 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {}"); 
+  verifyFormat("extern \"C\" {\n"
+   "int foo();\n"
+   "}");
+  verifyFormat("extern \"C\" int foo() {}");
+  verifyFormat("extern \"C\" int foo();");
+  verifyFormat("extern \"C\" int foo() {\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}");
+  
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("extern \"C\" int foo() {}", Style);
+  verifyFormat("extern \"C\" int foo();", Style);
+  verifyFormat("extern \"C\" int foo()\n" 
+   "{\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}", 
+   Style);
+  
+  Style.BraceWrapping.AfterExternBlock = true;
+  Style.BraceWrapping.SplitEmptyRecord = false;
+  verifyFormat("extern \"C\"\n" 
+   "{}", 
+   Style); 
+  verifyFormat("extern \"C\"\n" 
+   "{\n"
+   "  int foo();\n"
+   "}",
+   Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1039,7 +1039,12 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+if (Style.BraceWrapping.AfterExternBlock) {
+  addUnwrappedLine();
+  parseBlock(/*MustBeDeclaration=*/true);
+}
+else
+  parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
   }
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -233,7 +233,7 @@
   if (Tok && Tok->is(tok::kw_typedef))
 Tok = Tok->getNextNonComment();
   if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
-  Keywords.kw_interface))
+  tok::kw_extern, Keywords.kw_interface))
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
 ? tryMergeSimpleBlock(I, E, Limit) : 0;
 }
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -420,6 +420,7 @@
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
 IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
+IO.mapOptional("AfterExternBlock", Wrapping.AfterExternBlock);
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
@@ -501,8 +502,8 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false, true,
-true,  true};
+false, false, false, false, false, false,
+true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 Expanded.BraceWrapping.AfterClass = true;
@@ -515,6 +516,7 @@
 Expanded.BraceWrapping.AfterFunction = true;
 Expanded.BraceWrapping.AfterStruct = true;
 Expanded.BraceWrapping.AfterUnion = true;
+Expanded.BraceWrapping.AfterExternBlock = true;
 Expanded.BraceWrapping.SplitEmptyFunction = true;
 Expanded.BraceWrapping.SplitEmptyRecord = false;
 break;
@@ -531,13 +533,14 @@
 Expanded.BraceWrapping.AfterNamespace = true;
 Expanded.BraceWrapping.AfterObjCDeclaration = true;
 Expanded.BraceWrapping.AfterStruct = true;
+Expanded.BraceWrapping.AfterExternBlock = true;
 Expanded.BraceWrapping.BeforeCatch = true;
 Expanded.BraceWrapping.BeforeElse = 

[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

It turned out that removal range has to be even shorter than in 
https://reviews.llvm.org/D37566


Repository:
  rL LLVM

https://reviews.llvm.org/D37846



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


[PATCH] D37846: [clang-tidy] Fixed misc-unused-parameters omitting parameters square brackets

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
PriMee added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, JDevlieghere.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34449

**Problem:**

Clang-tidy check misc-unused-parameters comments out parameter name omitting 
following characters (e.g. square brackets) what results in its complete 
removal. Compilation errors might occur after clang-tidy fix as well.

**Patch description:**

Changed removal range. The range should end after parameter name, not after 
whole parameter declarator (which might be followed by e.g. square brackets).


Repository:
  rL LLVM

https://reviews.llvm.org/D37846

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -20,11 +20,21 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused 
[misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
+void d(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
+// CHECK-FIXES: {{^}}void d(int  /*i*/[]) {}{{$}}
+
+void e(int i[1]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
+// CHECK-FIXES: {{^}}void e(int  /*i*/[1]) {}{{$}}
+
 // Unchanged cases
 // ===
 void f(int i); // Don't remove stuff in declarations
 void g(int i = 1);
-void h(int i) { (void)i; } // Don't remove used parameters
+void h(int i[]);
+void s(int i[1]);
+void u(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
 static bool static_var = useLambda([] (int a) { return a; });
@@ -109,6 +119,9 @@
   static void g(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void g(int  /*i*/ = 1) {}
+  static void h(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void h(int  /*i*/[]) {}
 };
 
 namespace {
@@ -125,6 +138,9 @@
   void s(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void s(int  /*i*/ = 1) {}
+  void u(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void u(int  /*i*/[]) {}
 };
 
 void C::f(int i) {}
@@ -142,7 +158,8 @@
 // CHECK-FIXES: c.g();
 
   useFunction(::h);
-  useFunction(::s);;
+  useFunction(::s);
+  useFunction(::u);
 }
 
 class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,8 +138,7 @@
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(),
- Param->DeclaratorDecl::getSourceRange().getEnd());
+SourceRange RemovalRange(Param->getLocation(), Param->Decl::getLocation());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format 
will
 // clean this up afterwards.


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -20,11 +20,21 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
+void d(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void d(int  /*i*/[]) {}{{$}}
+
+void e(int i[1]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
+// CHECK-FIXES: {{^}}void e(int  /*i*/[1]) {}{{$}}
+
 // Unchanged cases
 // ===
 void f(int i); // Don't remove stuff in declarations
 void g(int i = 1);
-void h(int i) { (void)i; } // Don't remove used parameters
+void h(int i[]);
+void s(int i[1]);
+void u(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
 static bool static_var = useLambda([] (int a) { return a; });
@@ -109,6 +119,9 @@
   static void g(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void g(int  /*i*/ = 1) {}
+  static void h(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void h(int  /*i*/[]) {}
 };
 
 namespace {
@@ -125,6 +138,9 @@
   void s(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void s(int  /*i*/ = 1) {}
+  void u(int i[]) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void u(int  /*i*/[]) {}
 };
 
 

[PATCH] D37845: [clang-format] New flag - BraceWrapping.AfterExternC

2017-09-14 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: klimek.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **"extern C part"**

**Problem:**

Due to the lack of "brace wrapping extern" flag, clang format does parse the 
block after **extern** keyword moving the opening bracket to the header line 
always!

**Patch description:**

A new style added, new configuration flag - **BraceWrapping.AfterExternC** that 
allows us to decide whether we want a break before brace or not.


https://reviews.llvm.org/D37845

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

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -195,11 +195,11 @@
getGoogleStyle()));
   EXPECT_EQ("extern /**/ \"C\" /**/ {\n"
 "\n"
-"int i;\n"
+"  int i;\n"
 "}",
 format("extern /**/ \"C\" /**/ {\n"
"\n"
-   "inti;\n"
+   "  inti;\n"
"}",
getGoogleStyle()));
 
@@ -1704,7 +1704,42 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\n  int a;");
+  verifyFormat("extern \"C\" {}"); 
+  verifyFormat("extern \"C\" {\n"
+   "  int foo();\n"
+   "}");
+  verifyFormat("extern \"C\" int foo() {}");
+  verifyFormat("extern \"C\" int foo();");
+  verifyFormat("extern \"C\" int foo() {\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}");
+  
+  FormatStyle Style = getLLVMStyle();
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterFunction = true;
+  verifyFormat("extern \"C\" int foo() {}", Style);
+  verifyFormat("extern \"C\" int foo();", Style);
+  verifyFormat("extern \"C\" int foo()\n" 
+   "{\n"
+   "  int i = 42;\n"
+   "  return i;\n"
+   "}", 
+   Style);
+  
+  Style.BraceWrapping.AfterExternC = true;
+  Style.BraceWrapping.SplitEmptyRecord = false;
+  verifyFormat("extern \"C\"\n" 
+   "{}", 
+   Style); 
+  verifyFormat("extern \"C\"\n" 
+   "{\n"
+   "  int foo();\n"
+   "}",
+   Style);
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -1039,7 +1039,9 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
-parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
+if (Style.BraceWrapping.AfterExternC)
+  addUnwrappedLine();
+parseBlock(/*MustBeDeclaration=*/true);
 addUnwrappedLine();
 return;
   }
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -233,7 +233,7 @@
   if (Tok && Tok->is(tok::kw_typedef))
 Tok = Tok->getNextNonComment();
   if (Tok && Tok->isOneOf(tok::kw_class, tok::kw_struct, tok::kw_union,
-  Keywords.kw_interface))
+  tok::kw_extern, Keywords.kw_interface))
 return !Style.BraceWrapping.SplitEmptyRecord && EmptyBlock
 ? tryMergeSimpleBlock(I, E, Limit) : 0;
 }
Index: lib/Format/Format.cpp
===
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -420,6 +420,7 @@
 IO.mapOptional("AfterObjCDeclaration", Wrapping.AfterObjCDeclaration);
 IO.mapOptional("AfterStruct", Wrapping.AfterStruct);
 IO.mapOptional("AfterUnion", Wrapping.AfterUnion);
+IO.mapOptional("AfterExternC", Wrapping.AfterExternC);
 IO.mapOptional("BeforeCatch", Wrapping.BeforeCatch);
 IO.mapOptional("BeforeElse", Wrapping.BeforeElse);
 IO.mapOptional("IndentBraces", Wrapping.IndentBraces);
@@ -501,8 +502,8 @@
 return Style;
   FormatStyle Expanded = Style;
   Expanded.BraceWrapping = {false, false, false, false, false, false,
-false, false, false, false, false, true,
-true,  true};
+false, false, false, false, false, false,
+true,  true,  true};
   switch (Style.BreakBeforeBraces) {
   case FormatStyle::BS_Linux:
 

[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Great! I will work on it :)


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-12 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

A new style, e.g. **BraceWrapping.AfterExternC** option is what we are 
considering right now. It would probably handle the problem. Leaving the line 
break as is might be indeed a bad idea :)


https://reviews.llvm.org/D37260



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


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-11 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

ping


https://reviews.llvm.org/D37260



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


[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value

2017-09-11 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 114538.
PriMee added a comment.

Done :) Could you please commit this for me?


https://reviews.llvm.org/D37566

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused 
[misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,12 @@
 // CHECK-FIXES: staticFunctionC(2);
   staticFunctionD(1, 2, 3);
 // CHECK-FIXES: staticFunctionD(1, 3);
-  staticFunctionE();
+  staticFunctionE(1);
+// CHECK-FIXES: staticFunctionE();
+  staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();
+  staticFunctionF();
+// CHECK-FIXES: staticFunctionF();
 }
 
 /*
@@ -95,6 +106,9 @@
   static void f(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void f(int  /*i*/) {}
+  static void g(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void g(int  /*i*/ = 1) {}
 };
 
 namespace {
@@ -108,6 +122,9 @@
   void h(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void h(int  /*i*/) {}
+  void s(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void s(int  /*i*/ = 1) {}
 };
 
 void C::f(int i) {}
@@ -125,6 +142,7 @@
 // CHECK-FIXES: c.g();
 
   useFunction(::h);
+  useFunction(::s);;
 }
 
 class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,7 +138,8 @@
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
+SourceRange RemovalRange(Param->getLocation(),
+ Param->DeclaratorDecl::getSourceRange().getEnd());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format 
will
 // clean this up afterwards.


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,12 @@
 // CHECK-FIXES: staticFunctionC(2);
   staticFunctionD(1, 2, 3);
 // CHECK-FIXES: staticFunctionD(1, 3);
-  staticFunctionE();
+  staticFunctionE(1);
+// CHECK-FIXES: staticFunctionE();
+  staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();
+  staticFunctionF();
+// CHECK-FIXES: staticFunctionF();
 }
 
 /*
@@ 

[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-09-08 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Yes, would be great :) Thank you!


https://reviews.llvm.org/D37140



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


[PATCH] D37566: [clang-tidy] fixed misc-unused-parameters omitting parameters default value

2017-09-07 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: JDevlieghere.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34450

**Problem:**

Clang-tidy check misc-unused-parameters omits parameter default value what 
results in its complete removal. Compilation errors might occur after 
clang-tidy fix.

**Patch description:**

Changed removal range. The range should end after parameter declarator, not 
after whole parameter declaration (which might contain a default value).


https://reviews.llvm.org/D37566

Files:
  clang-tidy/misc/UnusedParametersCheck.cpp
  test/clang-tidy/misc-unused-parameters.cpp


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused 
[misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused 
[misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,10 @@
 // CHECK-FIXES: staticFunctionC(2);
   staticFunctionD(1, 2, 3);
 // CHECK-FIXES: staticFunctionD(1, 3);
-  staticFunctionE();
+  staticFunctionE(1);
+// CHECK-FIXES: staticFunctionE();
+  staticFunctionF(1);
+// CHECK-FIXES: staticFunctionF();
 }
 
 /*
@@ -95,6 +104,9 @@
   static void f(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:21: warning
 // CHECK-FIXES: static void f(int  /*i*/) {}
+  static void g(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning
+// CHECK-FIXES: static void g(int  /*i*/ = 1) {}
 };
 
 namespace {
@@ -108,6 +120,9 @@
   void h(int i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:14: warning
 // CHECK-FIXES: void h(int  /*i*/) {}
+  void s(int i = 1) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning
+// CHECK-FIXES: void s(int  /*i*/ = 1) {}
 };
 
 void C::f(int i) {}
@@ -125,6 +140,7 @@
 // CHECK-FIXES: c.g();
 
   useFunction(::h);
+  useFunction(::s);
 }
 
 class Base {
Index: clang-tidy/misc/UnusedParametersCheck.cpp
===
--- clang-tidy/misc/UnusedParametersCheck.cpp
+++ clang-tidy/misc/UnusedParametersCheck.cpp
@@ -138,7 +138,8 @@
   if (Function->isExternallyVisible() ||
   !Result.SourceManager->isInMainFile(Function->getLocation()) ||
   !Indexer->getOtherRefs(Function).empty() || isOverrideMethod(Function)) {
-SourceRange RemovalRange(Param->getLocation(), Param->getLocEnd());
+SourceRange RemovalRange(Param->getLocation(),
+ Param->DeclaratorDecl::getSourceRange().getEnd());
 // Note: We always add a space before the '/*' to not accidentally create a
 // '*/*' for pointer types, which doesn't start a comment. clang-format 
will
 // clean this up afterwards.


Index: test/clang-tidy/misc-unused-parameters.cpp
===
--- test/clang-tidy/misc-unused-parameters.cpp
+++ test/clang-tidy/misc-unused-parameters.cpp
@@ -14,15 +14,16 @@
 
 void b(int i = 1) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: parameter 'i' is unused [misc-unused-parameters]
-// CHECK-FIXES: {{^}}void b(int  /*i*/) {}{{$}}
+// CHECK-FIXES: {{^}}void b(int  /*i*/ = 1) {}{{$}}
 
 void c(int *i) {}
 // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: parameter 'i' is unused [misc-unused-parameters]
 // CHECK-FIXES: {{^}}void c(int * /*i*/) {}{{$}}
 
 // Unchanged cases
 // ===
-void g(int i); // Don't remove stuff in declarations
+void f(int i); // Don't remove stuff in declarations
+void g(int i = 1);
 void h(int i) { (void)i; } // Don't remove used parameters
 
 bool useLambda(int (*fn)(int));
@@ -52,6 +53,11 @@
 // CHECK-MESSAGES: :[[@LINE-1]]:33: warning
 // CHECK-FIXES: {{^}}static void staticFunctionE()
 
+static void staticFunctionF(int i = 4);
+// CHECK-FIXES: {{^}}static void staticFunctionF();
+static void staticFunctionF(int i) {}
+// CHECK-MESSAGES: :[[@LINE-1]]:33: warning
+// CHECK-FIXES: {{^}}static void staticFunctionF()
 
 static void someCallSites() {
   staticFunctionA(1);
@@ -62,7 +68,10 @@
 // 

[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-09-06 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added inline comments.



Comment at: lib/Format/UnwrappedLineFormatter.cpp:286
 }
+if (TheLine->Last->is(tok::l_brace) &&
+TheLine->First != TheLine->Last &&

PriMee wrote:
> krasimir wrote:
> > No tests fail if this `if` statement gets removed. Please either remove it 
> > or add a test for it.
> That's true. Why is that? Without this if statement tests would pass because 
> our block would have been handled by the construct I have mentioned in 
> problem description (Line 311). Adding a very similar test case with 
> BraceWrapping.AfterFunction flag changed would show that we need this if 
> statement. To my mind, it doesn't make sense to add such test case.
Okay, done. Now the test case would fail (Line 449 in FormatTest.cpp would be 
problematic, although in our case should NOT change anything).


https://reviews.llvm.org/D37140



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-09-06 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 113979.
PriMee added a comment.

Diff file again updated. Created against the newest commit.


https://reviews.llvm.org/D37140

Files:
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -439,19 +439,28 @@
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
   FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
+  AllowSimpleBracedStatements.ColumnLimit = 40;
   AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
 
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
   AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
 
+  AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
+  AllowSimpleBracedStatements.BraceWrapping.AfterFunction = true;
+  AllowSimpleBracedStatements.BraceWrapping.SplitEmptyRecord = false;
+
   verifyFormat("if (true) {}", AllowSimpleBracedStatements);
   verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements);
   verifyFormat("while (true) {}", AllowSimpleBracedStatements);
   verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
   verifyFormat("if (true) { f(); }", AllowSimpleBracedStatements);
   verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements);
   verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements);
   verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if (true) {\n"
+   "  ff();\n"
+   "}",
+   AllowSimpleBracedStatements);
   verifyFormat("if (true) { //\n"
"  f();\n"
"}",
@@ -482,6 +491,7 @@
AllowSimpleBracedStatements);
 
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
   verifyFormat("if (true) {\n"
"  f();\n"
"}",
@@ -494,14 +504,83 @@
AllowSimpleBracedStatements);
 
   AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = false;
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
   verifyFormat("while (true) {\n"
"  f();\n"
"}",
AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
   verifyFormat("for (;;) {\n"
"  f();\n"
"}",
AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
+  AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
+
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
+  verifyFormat("if (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  ff();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{ //\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "} else\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "} else\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = false;
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("while (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", 

[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-09-01 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a reviewer: krasimir.
PriMee added a subscriber: krasimir.
PriMee added a comment.

@krasimir Could you please tell me what did you mean in the comment:

> I am still not convinced about the extern part: some clients might prefer the 
> other style.

Do you suggest adding a new option, new style, like 
**BraceWrapping.AfterExtern** flag?


https://reviews.llvm.org/D37260



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-08-31 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Sorry for wrong formatting before. Some inline comments added.




Comment at: lib/Format/UnwrappedLineFormatter.cpp:286
 }
+if (TheLine->Last->is(tok::l_brace) &&
+TheLine->First != TheLine->Last &&

krasimir wrote:
> No tests fail if this `if` statement gets removed. Please either remove it or 
> add a test for it.
That's true. Why is that? Without this if statement tests would pass because 
our block would have been handled by the construct I have mentioned in problem 
description (Line 311). Adding a very similar test case with 
BraceWrapping.AfterFunction flag changed would show that we need this if 
statement. To my mind, it doesn't make sense to add such test case.



Comment at: lib/Format/UnwrappedLineFormatter.cpp:300
+  return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I-1, E, 
Limit) : 0;
+}
 if (TheLine->Last->is(tok::l_brace)) {

krasimir wrote:
> krasimir wrote:
> > Please reformat the newly added code with `clang-format`.
> Why in this case we use `Style.AllowShortBlocksOnASingleLine` and in the case 
> above we use `AfterControlStatement`?
> Also, why `tryMergeSimpleBlock` instead of `tryMergeControlStatement`?
We use `AfterControlStatement` because we want to ensure that the block with 
the opening brace in separate line is correct. The flag implies this fact. 
We use `tryMergeControlStatement` only when our control statement is not within 
braces, `tryMergeSimpleBlock` in every other case. 





Comment at: unittests/Format/FormatTest.cpp:537
+   "}",
+   AllowSimpleBracedStatements);
+

krasimir wrote:
> Why is this example not on a single line? Is it because it has an `else`?
Exactly. Shouldn't this work like that? There is a comment:
`// Don't merge "if (a) { .. } else {".` on line 548 in 
UnwrappedLineFormatter.cpp



https://reviews.llvm.org/D37140



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-08-31 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 113379.
PriMee added a comment.

Diff file updated. Some tests added. Some new bugs fixed as well :)


https://reviews.llvm.org/D37140

Files:
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -439,6 +439,7 @@
 
 TEST_F(FormatTest, FormatShortBracedStatements) {
   FormatStyle AllowSimpleBracedStatements = getLLVMStyle();
+  AllowSimpleBracedStatements.ColumnLimit = 40;
   AllowSimpleBracedStatements.AllowShortBlocksOnASingleLine = true;
 
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
@@ -452,6 +453,10 @@
   verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements);
   verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements);
   verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if (true) {\n"
+   "  ff();\n"
+   "}",
+   AllowSimpleBracedStatements);
   verifyFormat("if (true) { //\n"
"  f();\n"
"}",
@@ -482,6 +487,7 @@
AllowSimpleBracedStatements);
 
   AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
   verifyFormat("if (true) {\n"
"  f();\n"
"}",
@@ -494,14 +500,84 @@
AllowSimpleBracedStatements);
 
   AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = false;
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
   verifyFormat("while (true) {\n"
"  f();\n"
"}",
AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
   verifyFormat("for (;;) {\n"
"  f();\n"
"}",
AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
+  AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
+  AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
+
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
+  verifyFormat("if (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  ff();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{ //\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "} else\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "} else\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = false;
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("while (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
+  verifyFormat("for (;;)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
 }
 
 TEST_F(FormatTest, ParseIfElse) {
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -279,15 +279,41 @@
   }
 }
 
+// Try to merge a function block with left brace unwrapped
 if 

[PATCH] D37143: [clang-format] Fixed typedef enum brace wrapping

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

Could you change the "Contributed by" section? Wrong account is assigned. Full 
name would be more satisfying. Thank You in advance :)


Repository:
  rL LLVM

https://reviews.llvm.org/D37143



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


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 113074.
PriMee added a comment.

Unit tests added.


https://reviews.llvm.org/D37140

Files:
  lib/Format/UnwrappedLineFormatter.cpp
  unittests/Format/FormatTest.cpp

Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -486,9 +486,9 @@
"  f();\n"
"}",
AllowSimpleBracedStatements);
-  verifyFormat("if (true) {\n"
+  verifyFormat("if (true) {\n" 
"  f();\n"
-   "} else {\n"
+   "} else {\n" 
"  f();\n"
"}",
AllowSimpleBracedStatements);
@@ -498,7 +498,67 @@
"  f();\n"
"}",
AllowSimpleBracedStatements);
-  verifyFormat("for (;;) {\n"
+  verifyFormat("for (;;) {\n" 
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = true;
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = true;
+  AllowSimpleBracedStatements.BreakBeforeBraces = FormatStyle::BS_Custom;
+  AllowSimpleBracedStatements.BraceWrapping.AfterControlStatement = true;
+
+  verifyFormat("if (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("while (true) {}", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) {}", AllowSimpleBracedStatements);
+  verifyFormat("if (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if constexpr (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("while (true) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("for (;;) { f(); }", AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n" 
+   "{ //\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n" 
+   "{\n"
+   "  f();\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "} else\n" 
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortIfStatementsOnASingleLine = false;
+  verifyFormat("if (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("if (true)\n" 
+   "{\n"
+   "  f();\n"
+   "} else\n" 
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+
+  AllowSimpleBracedStatements.AllowShortLoopsOnASingleLine = false;
+  verifyFormat("while (true)\n"
+   "{\n"
+   "  f();\n"
+   "}",
+   AllowSimpleBracedStatements);
+  verifyFormat("for (;;)\n" 
+   "{\n"
"  f();\n"
"}",
AllowSimpleBracedStatements);
Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -283,13 +283,28 @@
 TheLine->First != TheLine->Last) {
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
 }
+if (TheLine->Last->is(tok::l_brace) &&
+TheLine->First != TheLine->Last &&
+TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+  return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
+if (I[1]->First->is(tok::l_brace) && 
+TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+  return Style.BraceWrapping.AfterControlStatement ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
+if (TheLine->First->is(tok::l_brace) &&
+   (TheLine->First == TheLine->Last) &&
+   (I != AnnotatedLines.begin()) &&
+   (I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for))) { 
+  return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I-1, E, Limit) : 0;
+}
 if (TheLine->Last->is(tok::l_brace)) {
   return !Style.BraceWrapping.AfterFunction
  ? tryMergeSimpleBlock(I, E, Limit)
  : 0;
 }
 if (I[1]->First->is(TT_FunctionLBrace) &&
-Style.BraceWrapping.AfterFunction) {
+Style.BraceWrapping.AfterFunction) { 
   if (I[1]->Last->is(TT_LineComment))
 return 0;
 
@@ -426,7 +441,7 @@
   SmallVectorImpl::const_iterator E,
   unsigned Limit) {
 AnnotatedLine  = **I;
-
+
 // Don't merge ObjC @ keywords and methods.
 // FIXME: If an option to allow short exception handling 

[PATCH] D37143: [clang-format] Fixed typedef enum brace wrapping

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

I am glad to hear that. Would be great if someone could commit it. Thank You :)


https://reviews.llvm.org/D37143



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


[PATCH] D37143: [clang-format] Fixed typedef enum brace wrapping

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 113062.
PriMee added a comment.

Done. 
**Extern C** part moved to: https://reviews.llvm.org/D37260


https://reviews.llvm.org/D37143

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1324,6 +1324,32 @@
   verifyFormat("enum X : std::uint32_t { A, B };");
 }
 
+TEST_F(FormatTest, FormatsTypedefEnum) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 40;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum {\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum\n"
+   "{\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+}
+
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2647,6 +2647,7 @@
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+   (Line.startsWith(tok::kw_typedef, tok::kw_enum) && 
Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) 
||
(Line.startsWith(tok::kw_struct) && 
Style.BraceWrapping.AfterStruct);
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1324,6 +1324,32 @@
   verifyFormat("enum X : std::uint32_t { A, B };");
 }
 
+TEST_F(FormatTest, FormatsTypedefEnum) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 40;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum {\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum\n"
+   "{\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+}
+
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2647,6 +2647,7 @@
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+   (Line.startsWith(tok::kw_typedef, tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
(Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37260: [clang-format] Fixed extern C brace wrapping

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: klimek.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34016 - **"extern C part"**

**Problem:**

Due to the lack of "brace wrapping extern" flag, clang format does parse the 
block after **extern** keyword moving the opening bracket to the header line 
**always**!

**Patch description:**

Added if statement handling the case when our **"extern block"** has the 
opening bracket in "non-header" line. Then forcing break before bracket.

**After fix:**

**CONFIG:**

  BreakBeforeBraces: Custom
  BraceWrapping: { 
  AfterClass: true, AfterControlStatement: true, AfterEnum: true, 
AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: 
true, BeforeCatch: true, BeforeElse: true 
  }

**BEFORE:**

  extern "C" 
  {
  #include 
  }

**AFTER:**

  extern "C" 
  {
  #include 
  }

**Remains the same!**

There is no brace wrapping flag that let us control opening brace's position. 
In case of other keywords (class, function, control statement etc.) we have 
opportunity to decide how should it look like. Here, we can't do it similarly. 
What we want is leaving braces **unformatted** (leave them as in the input), 
but what's more we still want to call **parseBlock** function. The only option 
is to set **MustBreakBefore** flag manually (only when needed, when the left 
brace is on non-header line, parseBlock does move it by default).


https://reviews.llvm.org/D37260

Files:
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1595,7 +1595,24 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {};");
+  EXPECT_EQ("extern \"C\" {\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\" {\n"
+   "int i = 42;\n"
+   "}"));
+  EXPECT_EQ("extern \"C\"\n" 
+"{\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\"\n" 
+   "{\n"
+   "int i = 42;\n"
+   "}"));
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  FormatTok->MustBreakBefore = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1595,7 +1595,24 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {};");
+  EXPECT_EQ("extern \"C\" {\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\" {\n"
+   "int i = 42;\n"
+   "}"));
+  EXPECT_EQ("extern \"C\"\n" 
+"{\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\"\n" 
+   "{\n"
+   "int i = 42;\n"
+   "}"));
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  FormatTok->MustBreakBefore = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37143: [clang-format] Fixed missing enter before bracket in typedef enum and extern

2017-08-29 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee updated this revision to Diff 113035.
PriMee added a comment.

Unit tests added. If there is indeed a necessity to separate these two cases 
just inform me :)


https://reviews.llvm.org/D37143

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1324,6 +1324,32 @@
   verifyFormat("enum X : std::uint32_t { A, B };");
 }
 
+TEST_F(FormatTest, FormatsTypedefEnum) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 40;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum {\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum\n"
+   "{\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+}
+
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
@@ -1595,7 +1621,25 @@
Style));
 }
 
-TEST_F(FormatTest, FormatsExternC) { verifyFormat("extern \"C\" {\nint a;"); }
+TEST_F(FormatTest, FormatsExternC) { 
+  verifyFormat("extern \"C\" {\nint a;");
+  verifyFormat("extern \"C\" {};");
+  EXPECT_EQ("extern \"C\" {\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\" {\n"
+   "int i = 42;\n"
+   "}"));
+  EXPECT_EQ("extern \"C\"\n" 
+"{\n"
+"int i = 42;\n"
+"}",
+format("extern \"C\"\n" 
+   "{\n"
+   "int i = 42;\n"
+   "}"));
+
+}
 
 TEST_F(FormatTest, FormatsInlineASM) {
   verifyFormat("asm(\"xyz\" : \"=a\"(a), \"=d\"(b) : \"a\"(data));");
Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  FormatTok->MustBreakBefore = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2647,6 +2647,7 @@
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+   (Line.startsWith(tok::kw_typedef, tok::kw_enum) && 
Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) 
||
(Line.startsWith(tok::kw_struct) && 
Style.BraceWrapping.AfterStruct);
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)


Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1324,6 +1324,32 @@
   verifyFormat("enum X : std::uint32_t { A, B };");
 }
 
+TEST_F(FormatTest, FormatsTypedefEnum) {
+  FormatStyle Style = getLLVMStyle();
+  Style.ColumnLimit = 40;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum {\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+  Style.BreakBeforeBraces = FormatStyle::BS_Custom;
+  Style.BraceWrapping.AfterEnum = true;
+  verifyFormat("typedef enum {} EmptyEnum;");
+  verifyFormat("typedef enum { A, B, C } ShortEnum;");
+  verifyFormat("typedef enum\n"
+   "{\n"
+   "  ZERO = 0,\n" 
+   "  ONE = 1,\n"
+   "  TWO = 2,\n"
+   "  THREE = 3\n"
+   "} LongEnum;",
+   Style);
+}
+
 TEST_F(FormatTest, FormatsNSEnums) {
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, SomeName) { AAA, BBB }");
   verifyGoogleFormat("typedef NS_ENUM(NSInteger, MyType) {\n"
@@ -1595,7 

[PATCH] D37143: [clang-format] Fixed missing enter before bracket in typedef enum and extern

2017-08-26 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee added a comment.

I merged them just because of their presence in the same bug report... As to 
the unit tests, I'll add them as soon as possible.

With reference to `extern` part, once again:
There is no brace wrapping flag that let us control opening brace's position. 
In case of other keywords (class, function, control statement etc.) we have 
opportunity to decide how should it look like. Here, we can't do it similarly. 
What we want is leaving braces **unformatted** (leave them as in the input), 
but what's more we still want to call **parseBlock** function. The only option 
is to set MustBreakBefore flag manually (only when needed, when the left brace 
is on non-header line, parseBlock does move it by default).

One more correction: Would be probably better to replace the line 
`MustBreakBeforeNextToken = true;` with `FormatTok->MustBreakBefore = true;`
It does work as expected as well (still passes every test - there are some!), 
but is more intuitive and understandable.

I'll work on these problems on monday.


https://reviews.llvm.org/D37143



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


[PATCH] D37143: [clang-format] Fixed missing enter before bracket in typedef enum and extern

2017-08-25 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: klimek.

Bug: https://bugs.llvm.org/show_bug.cgi?id=34016

**Problem:**

Clang format does not allow the flag **BraceWrapping.AfterEnum** control the 
case when our **enum** is preceded by **typedef** keyword (what is common in C 
language). 
Due to the lack of "brace wrapping extern" flag, clang format does parse the 
block after **extern** keyword moving the opening bracket to the header line 
**always**!

**Patch description:**

Added case to the **"AfterEnum"** flag when our enum does not start a line - is 
preceded by **typedef** keyword.
Added if statement handling the case when our **"extern block"** has the 
opening bracket in "non-header" line. Then forcing break before bracket.

**After fix:**

**BEFORE:**

  typedef enum 
  {
  a,
  b,
  c
  } SomeEnum;
  
  extern "C" 
  {
  #include 
  }

**AFTER:**

  typedef enum 
  {
  a,
  b,
  c
  } SomeEnum;
  
  extern "C" 
  {
  #include 
  }

**Remains the same!**


https://reviews.llvm.org/D37143

Files:
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp


Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  MustBreakBeforeNextToken = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2647,6 +2647,7 @@
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+   (Line.startsWith(tok::kw_typedef, tok::kw_enum) && 
Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) 
||
(Line.startsWith(tok::kw_struct) && 
Style.BraceWrapping.AfterStruct);
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)


Index: lib/Format/UnwrappedLineParser.cpp
===
--- lib/Format/UnwrappedLineParser.cpp
+++ lib/Format/UnwrappedLineParser.cpp
@@ -986,6 +986,8 @@
 if (FormatTok->Tok.is(tok::string_literal)) {
   nextToken();
   if (FormatTok->Tok.is(tok::l_brace)) {
+if (isOnNewLine(*FormatTok))
+  MustBreakBeforeNextToken = true;
 parseBlock(/*MustBeDeclaration=*/true, /*AddLevel=*/false);
 addUnwrappedLine();
 return;
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -2647,6 +2647,7 @@
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
 return (Line.startsWith(tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
+   (Line.startsWith(tok::kw_typedef, tok::kw_enum) && Style.BraceWrapping.AfterEnum) ||
(Line.startsWith(tok::kw_class) && Style.BraceWrapping.AfterClass) ||
(Line.startsWith(tok::kw_struct) && Style.BraceWrapping.AfterStruct);
   if (Left.is(TT_ObjCBlockLBrace) && !Style.AllowShortBlocksOnASingleLine)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D37140: [clang-format] Fixed one-line if statement

2017-08-25 Thread Pawel Maciocha via Phabricator via cfe-commits
PriMee created this revision.
Herald added a subscriber: klimek.

**Short overview:**

Fixed bug: https://bugs.llvm.org/show_bug.cgi?id=34001
Clang-format bug resulting in a strange behavior of control statements short 
blocks. Different flags combinations do not guarantee expected result. Turned 
on option AllowShortBlocksOnASingleLine does not work as intended.

**Description of the problem:**

Cpp source file UnwrappedLineFormatter does not handle 
AllowShortBlocksOnASingleLine flag as it should. Putting a single-line control 
statement without any braces, clang-format works as expected (depending on 
AllowShortIfStatementOnASingleLine or AllowShortLoopsOnASingleLine value). 
Putting a single-line control statement in braces, we can observe strange and 
incorrect behavior.
Our short block is intercepted by tryFitMultipleLinesInOne function. The 
function returns a number of lines to be merged. Unfortunately, our control 
statement block is not covered properly. There are several if-return 
statements, but none of them handles our block. A block is identified by the 
line first token and by left and right braces. A function block works as 
expected, there is such an if-return statement doing proper job. A control 
statement block, from the other hand, falls into strange conditional construct, 
which depends on BraceWrapping.AfterFunction flag (with condition that the 
line’s last token is left brace, what is possible in our case) or goes even 
further. That should definitely not happen.

**Description of the patch:**

By adding three different if statements, we guarantee that our short control 
statement block, however it looks like (different brace wrapping flags may be 
turned on), is handled properly and does not fall into wrong conditional 
construct. Depending on appropriate options we return either 0 (when something 
disturbs our merging attempt) or let another function (tryMergeSimpleBlock) 
take the responsibility of returned result (number of merged lines). 
Nevertheless, one more correction is required in mentioned tryMergeSimpleBlock 
function. The function, previously, returned either 0 or 2. The problem was 
that this did not handle the case when our block had the left brace in a 
separate line, not the header one. After change, after adding condition, we 
return the result compatible with block’s structure. In case of left brace in 
the header’s line we do everything as before the patch. In case of left brace 
in a separate line we do the job similar to the one we do in case of a 
“non-header left brace” function short block. To be precise, we try to merge 
the block ignoring the header line. Then, if success, we increment our returned 
result.

**After fix:**

**CONFIG:**

  AllowShortBlocksOnASingleLine: true 
  AllowShortIfStatementsOnASingleLine: true 
  BreakBeforeBraces: Custom
  BraceWrapping: { 
  AfterClass: true, AfterControlStatement: true, AfterEnum: true, 
AfterFunction: true, AfterNamespace: false, AfterStruct: true, AfterUnion: 
true, BeforeCatch: true, BeforeElse: true 
  }

**BEFORE:**

  if (statement) doSomething();
  if (statement) { doSomething(); }
  if (statement) {
  doSomething();
  }
  if (statement)
  {
  doSomething();
  }
  if (statement)
  doSomething();
  if (statement) {
  doSomething1();
  doSomething2();
  }

**AFTER:**

  if (statement) doSomething();
  if (statement) { doSomething(); }
  if (statement) { doSomething(); }
  if (statement) { doSomething(); }
  if (statement) doSomething();
  if (statement)
  {
doSomething1();
doSomething2();
  }


https://reviews.llvm.org/D37140

Files:
  lib/Format/UnwrappedLineFormatter.cpp

Index: lib/Format/UnwrappedLineFormatter.cpp
===
--- lib/Format/UnwrappedLineFormatter.cpp
+++ lib/Format/UnwrappedLineFormatter.cpp
@@ -283,6 +283,21 @@
 TheLine->First != TheLine->Last) {
   return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0;
 }
+if (TheLine->Last->is(tok::l_brace) &&
+TheLine->First != TheLine->Last &&
+TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+  return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
+if (I[1]->First->is(tok::l_brace) && 
+TheLine->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for)) { 
+  return Style.BraceWrapping.AfterControlStatement ? tryMergeSimpleBlock(I, E, Limit) : 0;
+}
+if (TheLine->First->is(tok::l_brace) &&
+   (TheLine->First == TheLine->Last) &&
+   (I != AnnotatedLines.begin()) &&
+   (I[-1]->First->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for))) { 
+  return Style.AllowShortBlocksOnASingleLine ? tryMergeSimpleBlock(I-1, E, Limit) : 0;
+}
 if (TheLine->Last->is(tok::l_brace)) {
   return !Style.BraceWrapping.AfterFunction
  ? tryMergeSimpleBlock(I, E, Limit)
@@ -459,53 +474,74 @@