diff options
author | Erik Pilkington <erik.pilkington@gmail.com> | 2016-07-27 18:25:10 +0000 |
---|---|---|
committer | Erik Pilkington <erik.pilkington@gmail.com> | 2016-07-27 18:25:10 +0000 |
commit | 3cdc317342d8c2b36de2839ea6ebefec17cb271e (patch) | |
tree | 80af2df7e2181aa85aa6ea80eb0f48d1e728ecf9 /clang/lib | |
parent | e921088c71cdc90dc31acc88d4e413706a5d9a42 (diff) | |
download | bcm5719-llvm-3cdc317342d8c2b36de2839ea6ebefec17cb271e.tar.gz bcm5719-llvm-3cdc317342d8c2b36de2839ea6ebefec17cb271e.zip |
[Sema] Teach getCurrentThisType to reconize lambda in in-class initializer
Fixes PR27994, a crash on valid.
Differential revision: https://reviews.llvm.org/D21145
llvm-svn: 276900
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExprCXX.cpp | 38 |
1 files changed, 16 insertions, 22 deletions
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 2cd00f8218a..b7a968e09d4 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -961,32 +961,26 @@ static QualType adjustCVQualifiersForCXXThisWithinLambda( QualType Sema::getCurrentThisType() { DeclContext *DC = getFunctionLevelDeclContext(); QualType ThisTy = CXXThisTypeOverride; + if (CXXMethodDecl *method = dyn_cast<CXXMethodDecl>(DC)) { if (method && method->isInstance()) ThisTy = method->getThisType(Context); } - if (ThisTy.isNull()) { - if (isGenericLambdaCallOperatorSpecialization(CurContext) && - CurContext->getParent()->getParent()->isRecord()) { - // This is a generic lambda call operator that is being instantiated - // within a default initializer - so use the enclosing class as 'this'. - // There is no enclosing member function to retrieve the 'this' pointer - // from. - - // FIXME: This looks wrong. If we're in a lambda within a lambda within a - // default member initializer, we need to recurse up more parents to find - // the right context. Looks like we should be walking up to the parent of - // the closure type, checking whether that is itself a lambda, and if so, - // recursing, until we reach a class or a function that isn't a lambda - // call operator. And we should accumulate the constness of *this on the - // way. - - QualType ClassTy = Context.getTypeDeclType( - cast<CXXRecordDecl>(CurContext->getParent()->getParent())); - // There are no cv-qualifiers for 'this' within default initializers, - // per [expr.prim.general]p4. - ThisTy = Context.getPointerType(ClassTy); - } + + if (ThisTy.isNull() && isLambdaCallOperator(CurContext) && + !ActiveTemplateInstantiations.empty()) { + + assert(isa<CXXRecordDecl>(DC) && + "Trying to get 'this' type from static method?"); + + // This is a lambda call operator that is being instantiated as a default + // initializer. DC must point to the enclosing class type, so we can recover + // the 'this' type from it. + + QualType ClassTy = Context.getTypeDeclType(cast<CXXRecordDecl>(DC)); + // There are no cv-qualifiers for 'this' within default initializers, + // per [expr.prim.general]p4. + ThisTy = Context.getPointerType(ClassTy); } // If we are within a lambda's call operator, the cv-qualifiers of 'this' |