Skip to content

Commit eafe98f

Browse files
authored
[clang-format] Always add a space after #if and #elif (llvm#81578)
Fixes llvm#81569.
1 parent 61c83e9 commit eafe98f

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1856,6 +1856,8 @@ class AnnotatingParser {
18561856
case tok::pp_elif:
18571857
Contexts.back().IsExpression = true;
18581858
next();
1859+
if (CurrentToken)
1860+
CurrentToken->SpacesRequiredBefore = true;
18591861
parseLine();
18601862
break;
18611863
default:

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16491,6 +16491,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
1649116491
verifyFormat("T A::operator()();", NoSpace);
1649216492
verifyFormat("X A::operator++(T);", NoSpace);
1649316493
verifyFormat("auto lambda = []() { return 0; };", NoSpace);
16494+
verifyFormat("#if (foo || bar) && baz\n"
16495+
"#elif ((a || b) && c) || d\n"
16496+
"#endif",
16497+
NoSpace);
1649416498

1649516499
FormatStyle Space = getLLVMStyle();
1649616500
Space.SpaceBeforeParens = FormatStyle::SBPO_Always;

0 commit comments

Comments
 (0)