[PATCH] D137181: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros
Noah Goldstein via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 1 14:17:45 PDT 2022
goldstein.w.n updated this revision to Diff 472397.
goldstein.w.n added a comment.
1. Updating D137181 <https://reviews.llvm.org/D137181>: [clang-format] Don't use 'PPIndentWidth' inside multi-line macros #
2. Enter a brief description of the changes included in this update.
3. The first line is used as subject, next lines as comment. #
4. If you intended to create a new revision, use:
5. $ arc diff --create
Added unit tests.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D137181/new/
https://reviews.llvm.org/D137181
Files:
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5021,6 +5021,7 @@
" int y = 0;\n"
"}\n",
style);
+
verifyFormat("#if 1\n"
" // some comments\n"
" // another\n"
@@ -5040,6 +5041,44 @@
" int y = 0;\n"
"}",
style);
+
+ style.ColumnLimit = 40;
+ style.IndentPPDirectives = FormatStyle::PPDIS_None;
+ verifyFormat("#ifdef foo\n"
+ "#define bar() \\\n"
+ " if (A) { \\\n"
+ " B(); \\\n"
+ " } \\\n"
+ " C();\n"
+ "#endif",
+ "#ifdef foo\n"
+ "#define bar() if (A) { B(); } C();\n"
+ "#endif",
+ style);
+ style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
+ verifyFormat("#ifdef foo\n"
+ "# define bar() \\\n"
+ " if (A) { \\\n"
+ " B(); \\\n"
+ " } \\\n"
+ " C();\n"
+ "#endif",
+ "#ifdef foo\n"
+ "#define bar() if (A) { B(); } C();\n"
+ "#endif",
+ style);
+ style.IndentPPDirectives = FormatStyle::PPDIS_BeforeHash;
+ verifyFormat("#ifdef foo\n"
+ " #define bar() \\\n"
+ " if (A) { \\\n"
+ " B(); \\\n"
+ " } \\\n"
+ " C();\n"
+ "#endif",
+ "#ifdef foo\n"
+ "#define bar() if (A) { B(); } C();\n"
+ "#endif",
+ style);
}
TEST_F(FormatTest, IndentsPPDirectiveInReducedSpace) {
Index: clang/lib/Format/UnwrappedLineFormatter.cpp
===================================================================
--- clang/lib/Format/UnwrappedLineFormatter.cpp
+++ clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -60,7 +60,7 @@
// Update the indent level cache size so that we can rely on it
// having the right size in adjustToUnmodifiedline.
skipLine(Line, /*UnknownIndent=*/true);
- if (Line.InPPDirective ||
+ if ((Line.InPPDirective && !Line.InMacroBody) ||
(Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
Line.Type == LT_CommentAbovePPDirective)) {
unsigned IndentWidth =
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137181.472397.patch
Type: text/x-patch
Size: 2552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221101/dd8e6256/attachment.bin>
More information about the cfe-commits
mailing list