Author: Owen Pan Date: 2024-02-13T22:35:52-08:00 New Revision: eafe98f937c790632452d1ab741477e4fb7e5531
URL: https://github.com/llvm/llvm-project/commit/eafe98f937c790632452d1ab741477e4fb7e5531 DIFF: https://github.com/llvm/llvm-project/commit/eafe98f937c790632452d1ab741477e4fb7e5531.diff LOG: [clang-format] Always add a space after #if and #elif (#81578) Fixes #81569. Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b9a000faae7cf7..08a49bc17f13f3 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -1856,6 +1856,8 @@ class AnnotatingParser { case tok::pp_elif: Contexts.back().IsExpression = true; next(); + if (CurrentToken) + CurrentToken->SpacesRequiredBefore = true; parseLine(); break; default: diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 13937a15fdaee2..79cd521b6a9998 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -16491,6 +16491,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) { verifyFormat("T A::operator()();", NoSpace); verifyFormat("X A::operator++(T);", NoSpace); verifyFormat("auto lambda = []() { return 0; };", NoSpace); + verifyFormat("#if (foo || bar) && baz\n" + "#elif ((a || b) && c) || d\n" + "#endif", + NoSpace); FormatStyle Space = getLLVMStyle(); Space.SpaceBeforeParens = FormatStyle::SBPO_Always; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits