diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/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; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/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"