diff options
| author | Daniel Jasper <djasper@google.com> | 2014-04-14 12:50:02 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2014-04-14 12:50:02 +0000 |
| commit | 72ab43b28b09401d48dfbcf8c79cdc7ea6fb44b5 (patch) | |
| tree | 9e530a2139ede1f22cd636cbf50bb31ddf76ae9d | |
| parent | 84aa310c82565b0f467250ec84917dc402608b0e (diff) | |
| download | bcm5719-llvm-72ab43b28b09401d48dfbcf8c79cdc7ea6fb44b5.tar.gz bcm5719-llvm-72ab43b28b09401d48dfbcf8c79cdc7ea6fb44b5.zip | |
clang-format: Fix incorrect &&-detection in macros.
Before:
#define A(a, b) (a &&b)
After:
#define A(a, b) (a && b)
This fixes llvm.org/PR19343.
llvm-svn: 206165
| -rw-r--r-- | clang/lib/Format/TokenAnnotator.cpp | 3 | ||||
| -rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 1 |
2 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index b81bf91c78b..410a84ecd2c 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -110,6 +110,9 @@ private: Left->Previous->Type == TT_BinaryOperator)) { // static_assert, if and while usually contain expressions. Contexts.back().IsExpression = true; + } else if (Line.InPPDirective && + (!Left->Previous || Left->Previous->isNot(tok::identifier))) { + Contexts.back().IsExpression = true; } else if (Left->Previous && Left->Previous->is(tok::r_square) && Left->Previous->MatchingParen && Left->Previous->MatchingParen->Type == TT_LambdaLSquare) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index f829dccbe98..a98e3d55556 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -4647,6 +4647,7 @@ TEST_F(FormatTest, UnderstandsRvalueReferences) { "};"); verifyGoogleFormat("#define IF(a, b, c) if (a && (b == c))"); verifyGoogleFormat("#define WHILE(a, b, c) while (a && (b == c))"); + verifyFormat("#define A(a, b) (a && b)"); } TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) { |

