r175439 - Correctly determine */& usage in more cases.
Daniel Jasper
djasper at google.com
Mon Feb 18 04:44:36 PST 2013
Author: djasper
Date: Mon Feb 18 06:44:35 2013
New Revision: 175439
URL: http://llvm.org/viewvc/llvm-project?rev=175439&view=rev
Log:
Correctly determine */& usage in more cases.
This fixes llvm.org/PR15248.
Before:
Test::Test(int b) : a(b *b) {}
for (int i = 0; i < a *a; ++i) {}
After:
Test::Test(int b) : a(b * b) {}
for (int i = 0; i < a * a; ++i) {}
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=175439&r1=175438&r2=175439&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Mon Feb 18 06:44:35 2013
@@ -503,6 +503,11 @@ private:
CurrentToken = &CurrentToken->Children[0];
else
CurrentToken = NULL;
+
+ // Reset token type in case we have already looked at it and then recovered
+ // from an error (e.g. failure to find the matching >).
+ if (CurrentToken != NULL)
+ CurrentToken->Type = TT_Unknown;
}
/// \brief A struct to hold information valid in a specific context, e.g.
@@ -558,6 +563,9 @@ private:
Previous && (Previous->is(tok::star) || Previous->is(tok::amp));
Previous = Previous->Parent)
Previous->Type = TT_PointerOrReference;
+ } else if (Current.Parent &&
+ Current.Parent->Type == TT_CtorInitializerColon) {
+ Contexts.back().IsExpression = true;
}
if (Current.Type == TT_Unknown) {
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=175439&r1=175438&r2=175439&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Feb 18 06:44:35 2013
@@ -1666,6 +1666,7 @@ TEST_F(FormatTest, UnderstandsNewAndDele
TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("int *f(int *a) {}");
verifyFormat("int main(int argc, char **argv) {}");
+ verifyFormat("Test::Test(int b) : a(b * b) {}");
verifyIndependentOfContext("f(a, *a);");
verifyIndependentOfContext("f(*a);");
verifyIndependentOfContext("int a = b * 10;");
@@ -1758,6 +1759,8 @@ TEST_F(FormatTest, UnderstandsUsesOfStar
" for (const int &v : Values) {\n"
" }\n"
"}");
+ verifyFormat("for (int i = a * a; i < 10; ++i) {\n}");
+ verifyFormat("for (int i = 0; i < a * a; ++i) {\n}");
verifyIndependentOfContext("A = new SomeType *[Length]();");
verifyGoogleFormat("A = new SomeType* [Length]();");
More information about the cfe-commits
mailing list