[PATCH] Mark lambda closure classes as being implicitly-generated.

James Dennett jdennett at google.com
Wed Sep 4 15:44:23 PDT 2013


  Remove redundant braces from an "if" statement.

Hi rsmith, dblaikie,

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

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1593?vs=4012&id=4047#toc

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,30 @@
                               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.3.patch
Type: text/x-patch
Size: 1528 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130904/fbdf4a4d/attachment.bin>


More information about the cfe-commits mailing list