[PATCH] D95644: Ensure that we traverse non-op() method bodys of lambdas
Stephen Kelly via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 28 16:49:55 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG43cc4f15008f: Ensure that we traverse non-op() method bodys of lambdas (authored by stephenkelly).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95644/new/
https://reviews.llvm.org/D95644
Files:
clang/include/clang/AST/RecursiveASTVisitor.h
clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
Index: clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
===================================================================
--- clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
+++ clang/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp
@@ -474,6 +474,42 @@
EXPECT_TRUE(notMatches("void f() { int z = 3; [&z](){}; }", HasCaptureThis));
}
+TEST(Matcher, MatchesMethodsOnLambda) {
+ StringRef Code = R"cpp(
+struct A {
+ ~A() {}
+};
+void foo()
+{
+ A a;
+ auto l = [a] { };
+ auto lCopy = l;
+ auto lPtrDecay = +[] { };
+ (void)lPtrDecay;
+}
+)cpp";
+
+ EXPECT_TRUE(matches(
+ Code, cxxConstructorDecl(
+ hasBody(compoundStmt()),
+ hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"))))),
+ isCopyConstructor())));
+ EXPECT_TRUE(matches(
+ Code, cxxConstructorDecl(
+ hasBody(compoundStmt()),
+ hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"))))),
+ isMoveConstructor())));
+ EXPECT_TRUE(matches(
+ Code, cxxDestructorDecl(
+ hasBody(compoundStmt()),
+ hasAncestor(lambdaExpr(hasAncestor(varDecl(hasName("l"))))))));
+ EXPECT_TRUE(matches(
+ Code, cxxConversionDecl(hasBody(compoundStmt(has(returnStmt(
+ hasReturnValue(implicitCastExpr()))))),
+ hasAncestor(lambdaExpr(hasAncestor(
+ varDecl(hasName("lPtrDecay"))))))));
+}
+
TEST(Matcher, isClassMessage) {
EXPECT_TRUE(matchesObjC(
"@interface NSString +(NSString *) stringWithFormat; @end "
Index: clang/include/clang/AST/RecursiveASTVisitor.h
===================================================================
--- clang/include/clang/AST/RecursiveASTVisitor.h
+++ clang/include/clang/AST/RecursiveASTVisitor.h
@@ -2062,7 +2062,8 @@
if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
if (const CXXRecordDecl *RD = MD->getParent()) {
- if (RD->isLambda()) {
+ if (RD->isLambda() &&
+ declaresSameEntity(RD->getLambdaCallOperator(), MD)) {
VisitBody = VisitBody && getDerived().shouldVisitLambdaBody();
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95644.320000.patch
Type: text/x-patch
Size: 2200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210129/7b2d4cee/attachment.bin>
More information about the cfe-commits
mailing list