diff options
| author | Manman Ren <manman.ren@gmail.com> | 2016-07-01 22:27:16 +0000 |
|---|---|---|
| committer | Manman Ren <manman.ren@gmail.com> | 2016-07-01 22:27:16 +0000 |
| commit | ebe8cf55ac975e092c4fff131346b304afeada72 (patch) | |
| tree | f0fb3b7b5deafa6be130318d5faa37650faf9526 /clang/lib/Sema/SemaExpr.cpp | |
| parent | ad56ea31294fd06475b99d0531f94566a1988c90 (diff) | |
| download | bcm5719-llvm-ebe8cf55ac975e092c4fff131346b304afeada72.tar.gz bcm5719-llvm-ebe8cf55ac975e092c4fff131346b304afeada72.zip | |
C++14 init-capture: error out instead of crashing.
When we have template arguments, we have a function and a pattern, the variable
in init-capture belongs to the pattern decl when checking if the lhs of
"max = current" is modifiable:
auto find = [max = init](auto current) {
max = current;
};
In function isReferenceToNonConstCapture, we handle the case where the decl
context for the variable is not part of the current context.
Instead of crashing, we emit an error message:
cannot assign to a variable captured by copy in a non-mutable lambda
rdar://26997922
llvm-svn: 274392
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index cc2a11fccfb..65d23418631 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -9653,7 +9653,16 @@ static NonConstCaptureKind isReferenceToNonConstCapture(Sema &S, Expr *E) { // Decide whether the first capture was for a block or a lambda. DeclContext *DC = S.CurContext, *Prev = nullptr; - while (DC != var->getDeclContext()) { + // Decide whether the first capture was for a block or a lambda. + while (DC) { + // For init-capture, it is possible that the variable belongs to the + // template pattern of the current context. + if (auto *FD = dyn_cast<FunctionDecl>(DC)) + if (var->isInitCapture() && + FD->getTemplateInstantiationPattern() == var->getDeclContext()) + break; + if (DC == var->getDeclContext()) + break; Prev = DC; DC = DC->getParent(); } |

