This revision was automatically updated to reflect the committed changes. Closed by commit rG892a9968ec77: [clang-format] Indent tokens after hash only if it starts a line (authored by owenpan).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D130136/new/ 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