forked from OSchip/llvm-project
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 llvm-svn: 190073
This commit is contained in:
parent
6c0af64f0c
commit
8f60cdd54b
|
@ -114,6 +114,7 @@ CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -522,4 +522,30 @@ TEST(RecursiveASTVisitor, HasCaptureDefaultLoc) {
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue