summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Bohme <mboehme@google.com>2016-07-26 15:19:10 +0000
committerMartin Bohme <mboehme@google.com>2016-07-26 15:19:10 +0000
commitd9a3521552ae6b2e8f475aeefe8cbf36d1f40f42 (patch)
tree5378060212fad9d32f024ee30ca3fef6eb8dbddb
parentdf5bcea08806580cd2a99b12c9fd7d428fd60004 (diff)
downloadbcm5719-llvm-d9a3521552ae6b2e8f475aeefe8cbf36d1f40f42.tar.gz
bcm5719-llvm-d9a3521552ae6b2e8f475aeefe8cbf36d1f40f42.zip
Make RecursiveASTVisitor visit lambda capture initialization expressions
Summary: Lambda capture initializations are part of the explicit source code and therefore should be visited by default but, so far, RecursiveASTVisitor does not visit them. This appears to be an oversight. Because the lambda body needs custom handling (calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets ShouldVisitChildren to false but then neglects to visit the lambda capture initializations. This patch adds code to visit the expressions associated with lambda capture initializations. Reviewers: klimek Subscribers: klimek, cfe-commits Differential Revision: https://reviews.llvm.org/D22566 llvm-svn: 276755
-rw-r--r--clang/include/clang/AST/RecursiveASTVisitor.h3
-rw-r--r--clang/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp8
2 files changed, 11 insertions, 0 deletions
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 71d7d19fed6..8c49785cd0f 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2266,6 +2266,9 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
C != CEnd; ++C) {
TRY_TO(TraverseLambdaCapture(S, C));
}
+ for (Expr *Init : S->capture_inits()) {
+ TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
+ }
TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
FunctionProtoTypeLoc Proto = TL.castAs<FunctionProtoTypeLoc>();
diff --git a/clang/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp b/clang/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
index 7b62fc1571a..d39ca4b39a7 100644
--- a/clang/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
+++ b/clang/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
@@ -191,6 +191,14 @@ TEST(RecursiveASTVisitor, VisitsCallExpr) {
"void x(); void y() { x(); }"));
}
+TEST(RecursiveASTVisitor, VisitsLambdaCaptureInit) {
+ DeclRefExprVisitor Visitor;
+ Visitor.ExpectMatch("i", 1, 20);
+ EXPECT_TRUE(Visitor.runOver(
+ "void f() { int i; [i]{}; };",
+ DeclRefExprVisitor::Lang_CXX11));
+}
+
/* FIXME: According to Richard Smith this is a bug in the AST.
TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
DeclRefExprVisitor Visitor;
OpenPOWER on IntegriCloud