1 // RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify
2 
3 // An attribute-specifier-seq in a lambda-declarator appertains to the
4 // type of the corresponding function call operator.
5 void test_attributes() {
6   auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{control may reach end of non-void lambda}}
7 
8   auto nrl2 = []() [[noreturn]] { return; }; // expected-error{{lambda declared 'noreturn' should not return}}
9 }
10 
11 template<typename T>
12 struct bogus_override_if_virtual : public T {
13   bogus_override_if_virtual() : T(*(T*)0) { }
14   int operator()() const;
15 };
16 
17 void test_quals() {
18   // This function call operator is declared const (9.3.1) if and only
19   // if the lambda- expression's parameter-declaration-clause is not
20   // followed by mutable.
21   auto l = [=](){}; // expected-note{{method is not marked volatile}}
22   const decltype(l) lc = l;
23   l();
24   lc();
25 
26   auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \
27                              // expected-note{{method is not marked volatile}}
28   const decltype(ml) mlc = ml;
29   ml();
30   mlc(); // expected-error{{no matching function for call to object of type}}
31 
32   // It is neither virtual nor declared volatile.
33   volatile decltype(l) lv = l;
34   volatile decltype(ml) mlv = ml;
35   lv(); // expected-error{{no matching function for call to object of type}}
36   mlv(); // expected-error{{no matching function for call to object of type}}
37 
38   bogus_override_if_virtual<decltype(l)> bogus;
39 }
40 
41 // Default arguments (8.3.6) shall not be specified in the
42 // parameter-declaration-clause of a lambda- declarator.
43 // Note: Removed by core issue 974.
44 int test_default_args() {
45   return [](int i = 5,  // expected-warning{{C++11 forbids default arguments for lambda expressions}}
46             int j = 17) { return i+j;}(5, 6);
47 }
48 
49 // Any exception-specification specified on a lambda-expression
50 // applies to the corresponding function call operator.
51 void test_exception_spec() {
52   auto tl1 = []() throw(int) {};
53   auto tl2 = []() {};
54   static_assert(!noexcept(tl1()), "lambda can throw");
55   static_assert(!noexcept(tl2()), "lambda can throw");
56 
57   auto ntl1 = []() throw() {};
58   auto ntl2 = []() noexcept(true) {};
59   auto ntl3 = []() noexcept {};
60   static_assert(noexcept(ntl1()), "lambda cannot throw");
61   static_assert(noexcept(ntl2()), "lambda cannot throw");
62   static_assert(noexcept(ntl3()), "lambda cannot throw");
63 }
64 
65