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 returned value of type 'X' to function return type '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 'float *' with an rvalue of type 'int'}}
77 template<typename R
, typename T
>
78 void odr_used(R
&r
, Boom
<T
> boom
) {
79 const std::type_info
&ti
80 = typeid([=,&r
] () -> R
& { // expected-error{{lambda expression in an unevaluated operand}}
86 template void odr_used(int&, Boom
<int>); // expected-note{{in instantiation of function template specialization}}
88 template<typename R
, typename T
>
89 void odr_used2(R
&r
, Boom
<T
> boom
) {
90 const std::type_info
&ti
91 = typeid([=,&r
] () -> R
& { // expected-note{{in instantiation of member function 'p2::Boom<float>::Boom' requested here}}
97 template void odr_used2(P
&, Boom
<float>);
101 struct NonConstCopy
{
102 NonConstCopy(const NonConstCopy
&) = delete;
103 NonConstCopy(NonConstCopy
&);
107 void double_capture(T
&nc
) {
115 template void double_capture(NonConstCopy
&);
118 namespace NonLocalLambdaInstantiation
{
125 int X
<T
>::value
= []{ return T(); }(); // expected-error{{cannot initialize a variable of type 'int' with an rvalue of type 'int *'}}
127 template int X
<int>::value
;
128 template int X
<float>::value
;
129 template int X
<int*>::value
; // expected-note{{in instantiation of static data member }}
132 void defaults(int x
= []{ return T(); }()) { }; // expected-error{{cannot initialize a parameter of type 'int' with an rvalue of type 'int *'}} \
133 // expected-note{{passing argument to parameter 'x' here}}
135 void call_defaults() {
138 defaults
<int*>(); // expected-note{{in instantiation of default function argument expression for 'defaults<int *>' required here}}
142 struct X2
{ // expected-note{{in instantiation of default member initializer 'NonLocalLambdaInstantiation::X2<int *>::x'}}
143 int x
= []{ return T(); }(); // expected-error{{cannot initialize a member subobject of type 'int' with an rvalue of type 'int *'}}
148 X2
<int*> x2ip
; // expected-note {{in evaluation of exception spec}}