[PATCH] D129921: [clang-format] Never remove braces in macro definitions

2022-07-16 Thread Owen Pan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGa0458d92e9e7: [clang-format] Never remove braces in macro 
definitions (authored by owenpan).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129921

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25803,6 +25803,13 @@
 
   Style.ColumnLimit = 20;
 
+  verifyFormat("int i;\n"
+   "#define FOO(a, b)  \\\n"
+   "  while (a) {  \\\n"
+   "b; \\\n"
+   "  }",
+   Style);
+
   verifyFormat("int ab = [](int i) {\n"
"  if (i > 0) {\n"
"i = 12345678 -\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,7 +539,7 @@
   break;
 case tok::r_brace:
   if (OpeningBrace) {
-if (!Style.RemoveBracesLLVM ||
+if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
 !OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
   return false;
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25803,6 +25803,13 @@
 
   Style.ColumnLimit = 20;
 
+  verifyFormat("int i;\n"
+   "#define FOO(a, b)  \\\n"
+   "  while (a) {  \\\n"
+   "b; \\\n"
+   "  }",
+   Style);
+
   verifyFormat("int ab = [](int i) {\n"
"  if (i > 0) {\n"
"i = 12345678 -\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,7 +539,7 @@
   break;
 case tok::r_brace:
   if (OpeningBrace) {
-if (!Style.RemoveBracesLLVM ||
+if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
 !OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D129921: [clang-format] Never remove braces in macro definitions

2022-07-16 Thread Marek Kurdej via Phabricator via cfe-commits
curdeius accepted this revision.
curdeius added a comment.
This revision is now accepted and ready to land.

Nice finding! LGTM


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D129921

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


[PATCH] D129921: [clang-format] Never remove braces in macro definitions

2022-07-15 Thread Owen Pan via Phabricator via cfe-commits
owenpan created this revision.
owenpan added reviewers: curdeius, HazardyKnusperkeks, MyDeveloperDay.
owenpan added a project: clang-format.
Herald added a project: All.
owenpan requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Fixes https://github.com/llvm/llvm-project/issues/56559.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129921

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


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25803,6 +25803,13 @@
 
   Style.ColumnLimit = 20;
 
+  verifyFormat("int i;\n"
+   "#define FOO(a, b)  \\\n"
+   "  while (a) {  \\\n"
+   "b; \\\n"
+   "  }",
+   Style);
+
   verifyFormat("int ab = [](int i) {\n"
"  if (i > 0) {\n"
"i = 12345678 -\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,7 +539,7 @@
   break;
 case tok::r_brace:
   if (OpeningBrace) {
-if (!Style.RemoveBracesLLVM ||
+if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
 !OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
   return false;
 }


Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -25803,6 +25803,13 @@
 
   Style.ColumnLimit = 20;
 
+  verifyFormat("int i;\n"
+   "#define FOO(a, b)  \\\n"
+   "  while (a) {  \\\n"
+   "b; \\\n"
+   "  }",
+   Style);
+
   verifyFormat("int ab = [](int i) {\n"
"  if (i > 0) {\n"
"i = 12345678 -\n"
Index: clang/lib/Format/UnwrappedLineParser.cpp
===
--- clang/lib/Format/UnwrappedLineParser.cpp
+++ clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,7 +539,7 @@
   break;
 case tok::r_brace:
   if (OpeningBrace) {
-if (!Style.RemoveBracesLLVM ||
+if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
 !OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
   return false;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits