r190073 - Mark lambda closure classes as being implicitly-generated.

James Dennett jdennett at google.com
Thu Sep 5 10:46:21 PDT 2013


Author: jdennett
Date: Thu Sep  5 12:46:21 2013
New Revision: 190073

URL: http://llvm.org/viewvc/llvm-project?rev=190073&view=rev
Log:
Mark lambda closure classes as being implicitly-generated.

Summary: 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.

Reviewers: rsmith, dblaikie

Reviewed By: dblaikie

CC: klimek, revane, cfe-commits, jordan_rose

Differential Revision: http://llvm-reviews.chandlerc.com/D1593

Modified:
    cfe/trunk/lib/AST/DeclCXX.cpp
    cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/lib/AST/DeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclCXX.cpp?rev=190073&r1=190072&r2=190073&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclCXX.cpp (original)
+++ cfe/trunk/lib/AST/DeclCXX.cpp Thu Sep  5 12:46:21 2013
@@ -114,6 +114,7 @@ CXXRecordDecl *CXXRecordDecl::CreateLamb
   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;
 }

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=190073&r1=190072&r2=190073&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Thu Sep  5 12:46:21 2013
@@ -522,4 +522,30 @@ TEST(RecursiveASTVisitor, HasCaptureDefa
                               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





More information about the cfe-commits mailing list