aboutsummaryrefslogtreecommitdiff
path: root/unittests/Tooling
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-05-02 00:30:48 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-05-02 00:30:48 +0000
commitc8c222830a1d8df8ed05bedfcac868fe6838fba8 (patch)
tree42282a8273a4dbc2acc967cd1a5b1f814a1b6b5f /unittests/Tooling
parente7958da55ec0ec66e56b6beed6c6ce24dbdc4075 (diff)
Unrevert r155951, reverted in r155962, with two changes:
* Work around build failures due to gcc 4.2 bugs. * Remove BodyIndexer::TraverseCXXOperatorCallExpr, which was not being called prior to this change, and whose presence disables a RecursiveASTVisitor stack space optimization after this change. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@155969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests/Tooling')
-rw-r--r--unittests/Tooling/RecursiveASTVisitorTest.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/unittests/Tooling/RecursiveASTVisitorTest.cpp b/unittests/Tooling/RecursiveASTVisitorTest.cpp
index d4fda73ccb..953817e61f 100644
--- a/unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ b/unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -165,6 +165,26 @@ public:
}
};
+class CXXOperatorCallExprTraverser
+ : public ExpectedLocationVisitor<CXXOperatorCallExprTraverser> {
+public:
+ // Use Traverse, not Visit, to check that data recursion optimization isn't
+ // bypassing the call of this function.
+ bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *CE) {
+ Match(getOperatorSpelling(CE->getOperator()), CE->getExprLoc());
+ return ExpectedLocationVisitor<CXXOperatorCallExprTraverser>::
+ TraverseCXXOperatorCallExpr(CE);
+ }
+};
+
+class ParenExprVisitor : public ExpectedLocationVisitor<ParenExprVisitor> {
+public:
+ bool VisitParenExpr(ParenExpr *Parens) {
+ Match("", Parens->getExprLoc());
+ return true;
+ }
+};
+
TEST(RecursiveASTVisitor, VisitsBaseClassDeclarations) {
TypeLocVisitor Visitor;
Visitor.ExpectMatch("class X", 1, 30);
@@ -345,4 +365,20 @@ TEST(RecursiveASTVisitor, NoRecursionInSelfFriend) {
"vector_iterator<int> it_int;\n"));
}
+TEST(RecursiveASTVisitor, TraversesOverloadedOperator) {
+ CXXOperatorCallExprTraverser Visitor;
+ Visitor.ExpectMatch("()", 4, 9);
+ EXPECT_TRUE(Visitor.runOver(
+ "struct A {\n"
+ " int operator()();\n"
+ "} a;\n"
+ "int k = a();\n"));
+}
+
+TEST(RecursiveASTVisitor, VisitsParensDuringDataRecursion) {
+ ParenExprVisitor Visitor;
+ Visitor.ExpectMatch("", 1, 9);
+ EXPECT_TRUE(Visitor.runOver("int k = (4) + 9;\n"));
+}
+
} // end namespace clang