Skip to content

Commit a98da3d

Browse files
committed
clang-format: Improve binary operator detection in macros.
Before: #define M(NAME) assert(!Context.Verifying &&#NAME); After: #define M(NAME) assert(!Context.Verifying && #NAME); This fixes llvm.org/PR16156. llvm-svn: 194216
1 parent 786d8a2 commit a98da3d

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ class AnnotatingParser {
620620
Contexts.back().InCtorInitializer = true;
621621
} else if (Current.is(tok::kw_new)) {
622622
Contexts.back().CanBeExpression = false;
623-
} else if (Current.is(tok::semi)) {
623+
} else if (Current.is(tok::semi) || Current.is(tok::exclaim)) {
624624
// This should be the condition or increment in a for-loop.
625625
Contexts.back().IsExpression = true;
626626
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
40814081
verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
40824082
verifyGoogleFormat("for (int i = 0; i * 2 < z; i *= 2) {\n}");
40834083

4084+
verifyFormat("#define A (!a * b)");
40844085
verifyFormat("#define MACRO \\\n"
40854086
" int *i = a * b; \\\n"
40864087
" void f(a *b);",

0 commit comments

Comments
 (0)