diff options
| author | Daniel Jasper <djasper@google.com> | 2013-05-03 14:41:24 +0000 |
|---|---|---|
| committer | Daniel Jasper <djasper@google.com> | 2013-05-03 14:41:24 +0000 |
| commit | c37de302192ba517fcd58606576c1e357d430766 (patch) | |
| tree | 5b559c22ca492ccd16c87f61512a61694903d197 /clang | |
| parent | ae426b4a619de2141ed5c5942cbf2aed591fe465 (diff) | |
| download | bcm5719-llvm-c37de302192ba517fcd58606576c1e357d430766.tar.gz bcm5719-llvm-c37de302192ba517fcd58606576c1e357d430766.zip | |
Fix expression recognition in for-loops.
Before: for (; a&& b;) {}
After: for (; a && b;) {}
llvm-svn: 181017
Diffstat (limited to 'clang')
| -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 3e67182f871..6fa79813fab 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -596,6 +596,9 @@ private: Contexts.back().IsExpression = true; } else if (Current.is(tok::kw_new)) { Contexts.back().CanBeExpression = false; + } else if (Current.is(tok::semi)) { + // This should be the condition or increment in a for-loop. + Contexts.back().IsExpression = true; } if (Current.Type == TT_Unknown) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 055b9d1cb28..abb2b5819c4 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2547,6 +2547,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) { verifyIndependentOfContext("A<int **, int **> a;"); verifyIndependentOfContext("void f(int *a = d * e, int *b = c * d);"); verifyFormat("for (char **a = b; *a; ++a) {\n}"); + verifyFormat("for (; a && b;) {\n}"); verifyFormat( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n" |

