diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-08-15 02:34:23 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2016-08-15 02:34:23 +0000 |
commit | 1879f1069b607b5cb3a16a0500bcb25e871d3b23 (patch) | |
tree | b10bbc4a902386968ddf26a938f1bdb88ecd07c0 /clang/lib | |
parent | 39a7c4c65afa08e620f14f52d5c67776c7f255f7 (diff) | |
download | bcm5719-llvm-1879f1069b607b5cb3a16a0500bcb25e871d3b23.tar.gz bcm5719-llvm-1879f1069b607b5cb3a16a0500bcb25e871d3b23.zip |
Disable lambda-capture of decomposition declaration bindings for now, until CWG
agrees on how they're supposed to work.
llvm-svn: 278648
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 2e53e3bd644..201248b3b35 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2838,6 +2838,10 @@ ExprResult Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, return ULE; } +static void +diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, + ValueDecl *var, DeclContext *DC); + /// \brief Complete semantic analysis for a reference to the given declaration. ExprResult Sema::BuildDeclarationNameExpr( const CXXScopeSpec &SS, const DeclarationNameInfo &NameInfo, NamedDecl *D, @@ -2981,7 +2985,12 @@ ExprResult Sema::BuildDeclarationNameExpr( // These are always lvalues. valueKind = VK_LValue; type = type.getNonReferenceType(); - // FIXME: Adjust cv-qualifiers for capture. + // FIXME: Support lambda-capture of BindingDecls, once CWG actually + // decides how that's supposed to work. + auto *BD = cast<BindingDecl>(VD); + if (BD->getDeclContext()->isFunctionOrMethod() && + BD->getDeclContext() != CurContext) + diagnoseUncapturableValueReference(*this, Loc, BD, CurContext); break; } @@ -13214,7 +13223,7 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func, static void diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, - VarDecl *var, DeclContext *DC) { + ValueDecl *var, DeclContext *DC) { DeclContext *VarDC = var->getDeclContext(); // If the parameter still belongs to the translation unit, then @@ -13234,25 +13243,21 @@ diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, if (!S.getLangOpts().CPlusPlus && !S.CurContext->isFunctionOrMethod()) return; + unsigned ValueKind = isa<BindingDecl>(var) ? 1 : 0; + unsigned ContextKind = 3; // unknown if (isa<CXXMethodDecl>(VarDC) && cast<CXXRecordDecl>(VarDC->getParent())->isLambda()) { - S.Diag(loc, diag::err_reference_to_local_var_in_enclosing_lambda) - << var->getIdentifier(); - } else if (FunctionDecl *fn = dyn_cast<FunctionDecl>(VarDC)) { - S.Diag(loc, diag::err_reference_to_local_var_in_enclosing_function) - << var->getIdentifier() << fn->getDeclName(); + ContextKind = 2; + } else if (isa<FunctionDecl>(VarDC)) { + ContextKind = 0; } else if (isa<BlockDecl>(VarDC)) { - S.Diag(loc, diag::err_reference_to_local_var_in_enclosing_block) - << var->getIdentifier(); - } else { - // FIXME: Is there any other context where a local variable can be - // declared? - S.Diag(loc, diag::err_reference_to_local_var_in_enclosing_context) - << var->getIdentifier(); + ContextKind = 1; } + S.Diag(loc, diag::err_reference_to_local_in_enclosing_context) + << var << ValueKind << ContextKind << VarDC; S.Diag(var->getLocation(), diag::note_entity_declared_at) - << var->getIdentifier(); + << var; // FIXME: Add additional diagnostic info about class etc. which prevents // capture. |