================
@@ -4937,17 +5003,49 @@ void UnwrappedLineParser::readToken(int 
LevelDifference) {
       // If there is an unfinished unwrapped line, we flush the preprocessor
       // directives only after that unwrapped line was finished later.
       bool SwitchToPreprocessorLines = !Line->Tokens.empty();
+      // Save CurrentLines before ScopedLineState may switch it to
+      // PreprocessorDirectives, so we can detect child-block contexts later.
+      const auto *OrigCurrentLines = CurrentLines;
       ScopedLineState BlockState(*this, SwitchToPreprocessorLines);
-      assert((LevelDifference >= 0 ||
-              static_cast<unsigned>(-LevelDifference) <= Line->Level) &&
-             "LevelDifference makes Line->Level negative");
-      Line->Level += LevelDifference;
-      // Comments stored before the preprocessor directive need to be output
-      // before the preprocessor directive, at the same level as the
-      // preprocessor directive, as we consider them to apply to the directive.
-      if (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHash &&
-          PPBranchLevel > 0) {
-        Line->Level += PPBranchLevel;
+      // For BeforeHashWithCode, the PP directive is indented at the 
surrounding
+      // code level. Apply LevelDifference to get the correct code context 
level
+      // (e.g. leaving a block), but do NOT apply PPBranchLevel since PP
+      // directives should align with the code rather than nesting PP levels.
+      if (Style.IndentPPDirectives == FormatStyle::PPDIS_BeforeHashWithCode) {
+        assert((LevelDifference >= 0 ||
----------------
HazardyKnusperkeks wrote:

The assert is the same in `if` and `else`.

https://github.com/llvm/llvm-project/pull/186686
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to