1 // RUN: %clang_cc1 -fsyntax-only -std=c++11 -Winvalid-noreturn %s -verify
4 void test_attributes() {
5 // FIXME: GCC accepts [[gnu::noreturn]] here.
6 auto nrl = []() [[gnu::noreturn]] {}; // expected-warning{{attribute 'noreturn' ignored}}
9 template void test_attributes<int>();
12 void call_with_zero() {
13 [](T *ptr) -> T& { return *ptr; }(0);
16 template void call_with_zero<int>();
19 T captures(T x, T y) {
20 auto lambda = [=, &y] () -> T {
35 template int captures(int, int);
36 template X captures(X, X);
39 int infer_result(T x, T y) {
40 auto lambda = [=](bool b) { return x + y; };
41 return lambda(true); // expected-error{{no viable conversion from 'X' to 'int'}}
44 template int infer_result(int, int);
45 template int infer_result(X, X); // expected-note{{in instantiation of function template specialization 'infer_result<X>' requested here}}
47 // Make sure that lambda's operator() can be used from templates.
49 void accept_lambda(F f) {
54 void pass_lambda(T x) {
55 accept_lambda([&x](T y) { return x + y; });
58 template void pass_lambda(int);
72 T* x = 1; // expected-error{{cannot initialize a variable of type 'int *' with an rvalue of type 'int'}} \
73 // expected-error{{cannot initialize a variable of type 'float *' with an rvalue of type 'int'}}
78 template<typename R, typename T>
79 void odr_used(R &r, Boom<T> boom) {
80 const std::type_info &ti
81 = typeid([=,&r] () -> R& { // expected-error{{lambda expression in an unevaluated operand}}
82 boom.tickle(); // expected-note{{in instantiation of member function}}
87 template void odr_used(int&, Boom<int>); // expected-note{{in instantiation of function template specialization}}
89 template<typename R, typename T>
90 void odr_used2(R &r, Boom<T> boom) {
91 const std::type_info &ti
92 = typeid([=,&r] () -> R& {
93 boom.tickle(); // expected-note{{in instantiation of member function}}
98 template void odr_used2(P&, Boom<float>);
102 struct NonConstCopy {
103 NonConstCopy(const NonConstCopy&) = delete;
104 NonConstCopy(NonConstCopy&);
108 void double_capture(T &nc) {
116 template void double_capture(NonConstCopy&);
119 namespace NonLocalLambdaInstantation {
126 int X<T>::value = []{ return T(); }(); // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'int *'}}
128 template int X<int>::value;
129 template int X<float>::value;
130 template int X<int*>::value; // expected-note{{in instantiation of static data member }}
133 void defaults(int x = []{ return T(); }()) { }; // expected-error{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}} \
134 // expected-note{{passing argument to parameter 'x' here}}
136 void call_defaults() {
139 defaults<int*>(); // expected-note{{in instantiation of default function argument expression for 'defaults<int *>' required here}}
144 int x = []{ return T(); }(); // expected-error{{cannot initialize a member subobject of type 'int' with an rvalue of type 'int *'}}
149 X2<int*> x2ip; // expected-note{{in instantiation of template class 'NonLocalLambdaInstantation::X2<int *>' requested here}}