| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify |
| Douglas Gregor | 6b8ef34 | 2012-02-01 17:18:19 +0000 | [diff] [blame] | 2 | |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 3 | // An attribute-specifier-seq in a lambda-declarator appertains to the |
| 4 | // type of the corresponding function call operator. |
| 5 | void test_attributes() { |
| Douglas Gregor | cf11eb7 | 2012-02-15 16:20:15 +0000 | [diff] [blame] | 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}} |
| Douglas Gregor | 6b8ef34 | 2012-02-01 17:18:19 +0000 | [diff] [blame] | 9 | } |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 10 | |
| 11 | template<typename T> |
| 12 | struct bogus_override_if_virtual : public T { |
| Douglas Gregor | 1a22d28 | 2012-02-12 17:34:23 +0000 | [diff] [blame] | 13 | bogus_override_if_virtual() : T(*(T*)0) { } |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 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. |
| Douglas Gregor | 1269510 | 2012-02-10 08:36:38 +0000 | [diff] [blame] | 21 | auto l = [=](){}; // expected-note{{method is not marked volatile}} |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 22 | const decltype(l) lc = l; |
| 23 | l(); |
| 24 | lc(); |
| 25 | |
| Douglas Gregor | 1269510 | 2012-02-10 08:36:38 +0000 | [diff] [blame] | 26 | auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \ |
| 27 | // expected-note{{method is not marked volatile}} |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 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. |
| Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 43 | // Note: Removed by core issue 974. |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 44 | int test_default_args() { |
| Douglas Gregor | adb376e | 2012-02-14 22:28:59 +0000 | [diff] [blame] | 45 | return [](int i = 5, // expected-warning{{C++11 forbids default arguments for lambda expressions}} |
| 46 | int j = 17) { return i+j;}(5, 6); |
| Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 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 | |