r190546 - clang-format: Fix bug in pointer detection
Daniel Jasper
djasper at google.com
Wed Sep 11 13:37:10 PDT 2013
Author: djasper
Date: Wed Sep 11 15:37:10 2013
New Revision: 190546
URL: http://llvm.org/viewvc/llvm-project?rev=190546&view=rev
Log:
clang-format: Fix bug in pointer detection
Before:
for (int i = 0; i* 2 < z; i *= 2) {}
After:
for (int i = 0; i * 2 < z; i *= 2) {}
Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=190546&r1=190545&r2=190546&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Sep 11 15:37:10 2013
@@ -574,7 +574,7 @@ private:
(!Current.Previous || Current.Previous->isNot(tok::kw_operator))) {
Contexts.back().IsExpression = true;
for (FormatToken *Previous = Current.Previous;
- Previous && Previous->isNot(tok::comma);
+ Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
if (Previous->is(tok::r_square))
Previous = Previous->MatchingParen;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=190546&r1=190545&r2=190546&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Sep 11 15:37:10 2013
@@ -3825,6 +3825,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
"}");
verifyFormat("for (int i = a * a; i < 10; ++i) {\n}");
verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
+ verifyGoogleFormat("for (int i = 0; i * 2 < z; i *= 2) {\n}");
verifyFormat("#define MACRO \\\n"
" int *i = a * b; \\\n"
More information about the cfe-commits
mailing list