aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorWei Pan <wei.pan@intel.com>2013-05-04 03:59:06 +0000
committerWei Pan <wei.pan@intel.com>2013-05-04 03:59:06 +0000
commit9fd6b8f5a73788f288edd01fa99d434d1e6588ad (patch)
tree9e9b626021de2b27472f3275c451c4d7d3e7f091 /test
parentcd904e8864637e427f5ea3bf35a26e79b3dbbadf (diff)
Implement template support for CapturedStmt
- Sema tests added and CodeGen tests are pending Differential Revision: http://llvm-reviews.chandlerc.com/D728 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@181101 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/SemaCXX/captured-statements.cpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/SemaCXX/captured-statements.cpp b/test/SemaCXX/captured-statements.cpp
index 15879a1ebc..dbb18a7b67 100644
--- a/test/SemaCXX/captured-statements.cpp
+++ b/test/SemaCXX/captured-statements.cpp
@@ -50,3 +50,117 @@ class test_this_capture {
{ b(); } // OK
}
};
+
+template <typename T>
+void template_capture_var() {
+ T x; // expected-error{{declaration of reference variable 'x' requires an initializer}}
+ #pragma clang _debug captured
+ {
+ (void)x;
+ }
+}
+
+template <typename T>
+class Val {
+ T v;
+public:
+ void set(const T &v0) {
+ #pragma clang __debug captured
+ {
+ v = v0;
+ }
+ }
+};
+
+void test_capture_var() {
+ template_capture_var<int>(); // OK
+ template_capture_var<int&>(); // expected-note{{in instantiation of function template specialization 'template_capture_var<int &>' requested here}}
+
+ Val<float> Obj;
+ Obj.set(0.0f); // OK
+}
+
+template <typename S, typename T>
+S template_capture_var(S x, T y) {
+ #pragma clang _debug captured
+ {
+ x++;
+ y++; // expected-error{{read-only variable is not assignable}}
+ }
+
+ return x;
+}
+
+// Check if can recover from a template error.
+void test_capture_var_error() {
+ template_capture_var<int, int>(0, 1); // OK
+ template_capture_var<int, const int>(0, 1); // expected-note{{in instantiation of function template specialization 'template_capture_var<int, const int>' requested here}}
+ template_capture_var<int, int>(0, 1); // OK
+}
+
+template <typename T>
+void template_capture_in_lambda() {
+ T x, y;
+ [=, &y]() {
+ #pragma clang __debug captured
+ {
+ y += x;
+ }
+ }();
+}
+
+void test_lambda() {
+ template_capture_in_lambda<int>(); // OK
+}
+
+struct Foo {
+ void foo() { }
+ static void bar() { }
+};
+
+template <typename T>
+void template_capture_func(T &t) {
+ #pragma clang __debug captured
+ {
+ t.foo();
+ }
+
+ #pragma clang __debug captured
+ {
+ T::bar();
+ }
+}
+
+void test_template_capture_func() {
+ Foo Obj;
+ template_capture_func(Obj);
+}
+
+template <typename T>
+T captured_sum(const T &a, const T &b) {
+ T result;
+
+ #pragma clang __debug captured
+ {
+ result = a + b;
+ }
+
+ return result;
+}
+
+template <typename T, typename... Args>
+T captured_sum(const T &a, const Args&... args) {
+ T result;
+
+ #pragma clang __debug captured
+ {
+ result = a + captured_sum(args...);
+ }
+
+ return result;
+}
+
+void test_capture_variadic() {
+ (void)captured_sum(1, 2, 3); // OK
+ (void)captured_sum(1, 2, 3, 4, 5); // OK
+}