[PATCH] Mark lambda closure classes as being implicitly-generated.
James Dennett
jdennett at google.com
Tue Sep 3 22:55:56 PDT 2013
jdennett added you to the CC list for the revision "Mark lambda closure classes as being implicitly-generated.".
Hi rsmith, dblaikie,
Closure classes for C++ lambdas are always compiler-generated. This one-line change calls setImplicit(true) on them at creation time, such that a default RecursiveASTVisitor (or any for which shouldVisitImplicitCode returns false) will skip them.
http://llvm-reviews.chandlerc.com/D1593
Files:
lib/AST/DeclCXX.cpp
unittests/Tooling/RecursiveASTVisitorTest.cpp
Index: lib/AST/DeclCXX.cpp
===================================================================
--- lib/AST/DeclCXX.cpp
+++ lib/AST/DeclCXX.cpp
@@ -103,6 +103,7 @@
R->IsBeingDefined = true;
R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, Dependent);
R->MayHaveOutOfDateDef = false;
+ R->setImplicit(true);
C.getTypeDeclType(R, /*PrevDecl=*/0);
return R;
}
Index: unittests/Tooling/RecursiveASTVisitorTest.cpp
===================================================================
--- unittests/Tooling/RecursiveASTVisitorTest.cpp
+++ unittests/Tooling/RecursiveASTVisitorTest.cpp
@@ -522,4 +522,31 @@
LambdaDefaultCaptureVisitor::Lang_CXX11));
}
+// Checks for lambda classes that are not marked as implicitly-generated.
+// (There should be none.)
+class ClassVisitor : public ExpectedLocationVisitor<ClassVisitor> {
+public:
+ ClassVisitor() : SawNonImplicitLambdaClass(false) {}
+ bool VisitCXXRecordDecl(CXXRecordDecl* record) {
+ if (record->isLambda() && !record->isImplicit()) {
+ SawNonImplicitLambdaClass = true;
+ }
+ return true;
+ }
+
+ bool sawOnlyImplicitLambdaClasses() const {
+ return !SawNonImplicitLambdaClass;
+ }
+
+private:
+ bool SawNonImplicitLambdaClass;
+};
+
+TEST(RecursiveASTVisitor, LambdaClosureTypesAreImplicit) {
+ ClassVisitor Visitor;
+ EXPECT_TRUE(Visitor.runOver("auto lambda = []{};",
+ ClassVisitor::Lang_CXX11));
+ EXPECT_TRUE(Visitor.sawOnlyImplicitLambdaClasses());
+}
+
} // end namespace clang
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1593.2.patch
Type: text/x-patch
Size: 1537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130903/fe2c486e/attachment.bin>
More information about the cfe-commits
mailing list