aboutsummaryrefslogtreecommitdiff
path: root/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2012-02-14 00:00:48 +0000
committerDouglas Gregor <dgregor@apple.com>2012-02-14 00:00:48 +0000
commitd5387e86ce3dfe1ae09e050ee11d86ca0d066d04 (patch)
treedc324b8b16eac75b96b3b03e86a30595eb60ff0d /test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp
parente76872e81ea32fbc863d8d7ef6eadc91a8f8673b (diff)
Link together the call operator produced from transforming a lambda
expression with the original call operator, so that we don't try to separately instantiate the call operator. Test and tweak a few more bits for template instantiation of lambda expressions. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150440 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp')
-rw-r--r--test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp71
1 files changed, 71 insertions, 0 deletions
diff --git a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp b/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp
index 4126dd96b9..baa29ea944 100644
--- a/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp
+++ b/test/CXX/expr/expr.prim/expr.prim.lambda/templates.cpp
@@ -43,3 +43,74 @@ int infer_result(T x, T y) {
template int infer_result(int, int);
template int infer_result(X, X); // expected-note{{in instantiation of function template specialization 'infer_result<X>' requested here}}
+// Make sure that lambda's operator() can be used from templates.
+template<typename F>
+void accept_lambda(F f) {
+ f(1);
+}
+
+template<typename T>
+void pass_lambda(T x) {
+ accept_lambda([&x](T y) { return x + y; });
+}
+
+template void pass_lambda(int);
+
+namespace std {
+ class type_info;
+}
+
+namespace p2 {
+ struct P {
+ virtual ~P();
+ };
+
+ template<typename T>
+ struct Boom {
+ Boom(const Boom&) {
+ T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \
+ // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}}
+ }
+ void tickle() const;
+ };
+
+ template<typename R, typename T>
+ void odr_used(R &r, Boom<T> boom) {
+ const std::type_info &ti
+ = typeid([=,&r] () -> R& { // expected-error{{lambda expression in an unevaluated operand}}
+ boom.tickle(); // expected-note{{in instantiation of member function}}
+ return r;
+ }());
+ }
+
+ template void odr_used(int&, Boom<int>); // expected-note{{in instantiation of function template specialization}}
+
+ template<typename R, typename T>
+ void odr_used2(R &r, Boom<T> boom) {
+ const std::type_info &ti
+ = typeid([=,&r] () -> R& {
+ boom.tickle(); // expected-note{{in instantiation of member function}}
+ return r;
+ }());
+ }
+
+ template void odr_used2(P&, Boom<float>);
+}
+
+namespace p5 {
+ struct NonConstCopy {
+ NonConstCopy(const NonConstCopy&) = delete;
+ NonConstCopy(NonConstCopy&);
+ };
+
+ template<typename T>
+ void double_capture(T &nc) {
+ [=] () mutable {
+ [=] () mutable {
+ T nc2(nc);
+ }();
+ }();
+ }
+
+ template void double_capture(NonConstCopy&);
+}