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/test/SemaCXX/cxx1y-init-captures.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/test/SemaCXX/cxx1y-init-captures.cpp')
| -rw-r--r-- | clang/test/SemaCXX/cxx1y-init-captures.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/clang/test/SemaCXX/cxx1y-init-captures.cpp b/clang/test/SemaCXX/cxx1y-init-captures.cpp index d36882d8e5d..d681954707d 100644 --- a/clang/test/SemaCXX/cxx1y-init-captures.cpp +++ b/clang/test/SemaCXX/cxx1y-init-captures.cpp @@ -196,3 +196,13 @@ namespace N3922 { auto a = [x{X()}] { return x.n; }; // ok auto b = [x = {X()}] {}; // expected-error{{<initializer_list>}} } + +namespace init_capture_non_mutable { +void test(double weight) { + double init; + auto find = [max = init](auto current) { + max = current; // expected-error{{cannot assign to a variable captured by copy in a non-mutable lambda}} + }; + find(weight); // expected-note {{in instantiation of function template specialization}} +} +} |

