[PATCH] D130136: [clang-format] Indent tokens after hash only if it starts a line
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 19 18:14:08 PDT 2022
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/56602.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D130136
Files:
clang/lib/Format/ContinuationIndenter.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -5385,6 +5385,10 @@
"#endif",
Style);
Style.IndentPPDirectives = FormatStyle::PPDIS_AfterHash;
+ verifyFormat("#if 1\n"
+ "# define __STR(x) #x\n"
+ "#endif",
+ Style);
verifyFormat("#ifdef _WIN32\n"
"# define A 0\n"
"# ifdef VAR2\n"
Index: clang/lib/Format/ContinuationIndenter.cpp
===================================================================
--- clang/lib/Format/ContinuationIndenter.cpp
+++ clang/lib/Format/ContinuationIndenter.cpp
@@ -656,6 +656,7 @@
int PPColumnCorrection = 0;
if (Style.IndentPPDirectives == FormatStyle::PPDIS_AfterHash &&
Previous.is(tok::hash) && State.FirstIndent > 0 &&
+ &Previous == State.Line->First &&
(State.Line->Type == LT_PreprocessorDirective ||
State.Line->Type == LT_ImportStatement)) {
Spaces += State.FirstIndent;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130136.445999.patch
Type: text/x-patch
Size: 1117 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220720/81cd1044/attachment-0001.bin>
More information about the cfe-commits
mailing list