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;
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;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits