diff options
author | Daniel Jasper <djasper@google.com> | 2013-02-18 12:44:35 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2013-02-18 12:44:35 +0000 |
commit | d0f349be1422a123fdb28d6dd556f7300e6d51e9 (patch) | |
tree | f21a06795a4e0c11ce3c26807b3fd676ae01a6c1 | |
parent | 6a93c86fc73d84a40d3460be04444669c8439e20 (diff) |
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) {}
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175439 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Format/TokenAnnotator.cpp | 8 | ||||
-rw-r--r-- | unittests/Format/FormatTest.cpp | 3 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 25b3a24704..19582f2ed2 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -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) { diff --git a/unittests/Format/FormatTest.cpp b/unittests/Format/FormatTest.cpp index 19e34df681..c63d7566a9 100644 --- a/unittests/Format/FormatTest.cpp +++ b/unittests/Format/FormatTest.cpp @@ -1666,6 +1666,7 @@ TEST_F(FormatTest, UnderstandsNewAndDelete) { 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, UnderstandsUsesOfStarAndAmp) { " 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]();"); |