[clang] New indent pp directives before hash with code (PR #186686)
Björn Schäpers via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 15 12:38:11 PDT 2026
================
@@ -4651,7 +4697,27 @@ void UnwrappedLineParser::addUnwrappedLine(LineLevel AdjustLevel) {
// At the top level we only get here when no unexpansion is going on, or
// when conditional formatting led to unfinished macro reconstructions.
assert(!Reconstruct || (CurrentLines != &Lines) || !PPStack.empty());
+ // For BeforeHashWithCode, code lines inside PP conditional blocks must be
+ // indented by the PP nesting depth so that code appears more indented than
+ // its enclosing PP directive (mirroring how C++ block content is indented
+ // relative to the opening brace). PP directive lines already have
+ // PPBranchLevel+1 added in parsePPUnknown; code lines need the same
+ // treatment. We temporarily adjust Level here and restore it afterwards so
+ // that the next line still starts from the correct C++ brace level.
+ // For BeforeHashWithCode, code lines inside PP blocks need their level
+ // raised to match the enclosing PP directive's nesting depth. Using
+ // Line->PPLevel (set at first-token push time) instead of the current
+ // PPBranchLevel, which may have been altered by later PP directives that
+ // readToken processed after the code tokens but before addUnwrappedLine.
+ const bool BWHCCodeLine =
+ Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHashWithCode &&
+ !Line->InPPDirective && Line->PPLevel > 0;
+ const unsigned PPAdj = BWHCCodeLine ? Line->PPLevel : 0;
----------------
HazardyKnusperkeks wrote:
This needs to have a better name.
https://github.com/llvm/llvm-project/pull/186686
More information about the cfe-commits
mailing list