summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2015-04-27 21:27:54 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2015-04-27 21:27:54 +0000
commitc38498f0469aba6a0fb63d99ad398cdf788c5696 (patch)
treeed7df3fc6de1b03134e8350a770ac565f5824b60 /clang/test/SemaCXX
parent5b395243132dc3463c23daea1f215237565ce85f (diff)
downloadbcm5719-llvm-c38498f0469aba6a0fb63d99ad398cdf788c5696.tar.gz
bcm5719-llvm-c38498f0469aba6a0fb63d99ad398cdf788c5696.zip
PR23334: Perform semantic checking of lambda capture initialization in the right context.
Previously we'd try to perform checks on the captures from the middle of parsing the lambda's body, at the point where we detected that a variable needed to be captured. This was wrong in a number of subtle ways. In PR23334, we couldn't correctly handle the list of potential odr-uses resulting from the capture, and our attempt to recover from that resulted in a use-after-free. We now defer building the initialization expression until we leave the lambda body and return to the enclosing context, where the initialization does the right thing. This patch only covers lambda-expressions, but we should apply the same change to blocks and captured statements too. llvm-svn: 235921
Diffstat (limited to 'clang/test/SemaCXX')
-rw-r--r--clang/test/SemaCXX/PR23334.cpp10
-rw-r--r--clang/test/SemaCXX/cxx1y-generic-lambdas.cpp6
-rw-r--r--clang/test/SemaCXX/uninitialized.cpp9
3 files changed, 23 insertions, 2 deletions
diff --git a/clang/test/SemaCXX/PR23334.cpp b/clang/test/SemaCXX/PR23334.cpp
new file mode 100644
index 00000000000..cd6b4f4551f
--- /dev/null
+++ b/clang/test/SemaCXX/PR23334.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++11 -verify %s -Wno-unused
+
+// This must be at the start of the file (the failure depends on a SmallPtrSet
+// not having been reallocated yet).
+void fn1() {
+ // expected-no-diagnostics
+ constexpr int kIsolationClass = 0;
+ const int kBytesPerConnection = 0;
+ [=] { kIsolationClass, kBytesPerConnection, kBytesPerConnection; };
+}
diff --git a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
index 90ecf6904e5..f4c67fbba0c 100644
--- a/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
+++ b/clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
@@ -899,8 +899,10 @@ struct X1 {
int L2 = ([](auto i) { return i; })(2);
void fooG(T i = ([] (auto i) { return i; })(2)) { }
int BG : ([](auto i) { return i; })(3); //expected-error{{not an integral constant}}\
- //expected-note{{non-literal type}}
- int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}}
+ //expected-note{{non-literal type}}\
+ //expected-error{{inside of a constant expression}}
+ int arrG[([](auto i) { return i; })(3)]; //expected-error{{must have a constant size}} \
+ //expected-error{{inside of a constant expression}}
int (*fpG)(T) = [](auto i) { return i; };
void fooptrG(T (*fp)(char) = [](auto c) { return 0; }) { }
template<class U = char> int fooG2(T (*fp)(U) = [](auto a) { return 0; }) { return 0; }
diff --git a/clang/test/SemaCXX/uninitialized.cpp b/clang/test/SemaCXX/uninitialized.cpp
index f02357419f5..5769a0c028c 100644
--- a/clang/test/SemaCXX/uninitialized.cpp
+++ b/clang/test/SemaCXX/uninitialized.cpp
@@ -1428,3 +1428,12 @@ class A {
A(int (*) [7]) : a(rvalueref::notmove(a)) {}
};
}
+
+void array_capture(bool b) {
+ const char fname[] = "array_capture";
+ if (b) {
+ int unused; // expected-warning {{unused variable}}
+ } else {
+ [fname]{};
+ }
+}
OpenPOWER on IntegriCloud