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() { |
| 6 | auto nrl = []() [[noreturn]] {}; // expected-warning{{function declared 'noreturn' should not return}} |
Douglas Gregor | 6b8ef34 | 2012-02-01 17:18:19 +0000 | [diff] [blame] | 7 | } |
Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 8 | |
| 9 | template<typename T> |
| 10 | struct bogus_override_if_virtual : public T { |
| 11 | int operator()() const; |
| 12 | }; |
| 13 | |
| 14 | void test_quals() { |
| 15 | // This function call operator is declared const (9.3.1) if and only |
| 16 | // if the lambda- expression's parameter-declaration-clause is not |
| 17 | // followed by mutable. |
Douglas Gregor | 1269510 | 2012-02-10 08:36:38 +0000 | [diff] [blame] | 18 | auto l = [=](){}; // expected-note{{method is not marked volatile}} |
Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 19 | const decltype(l) lc = l; |
| 20 | l(); |
| 21 | lc(); |
| 22 | |
Douglas Gregor | 1269510 | 2012-02-10 08:36:38 +0000 | [diff] [blame] | 23 | auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \ |
| 24 | // expected-note{{method is not marked volatile}} |
Douglas Gregor | a30a0bc | 2012-02-09 18:19:44 +0000 | [diff] [blame] | 25 | const decltype(ml) mlc = ml; |
| 26 | ml(); |
| 27 | mlc(); // expected-error{{no matching function for call to object of type}} |
| 28 | |
| 29 | // It is neither virtual nor declared volatile. |
| 30 | volatile decltype(l) lv = l; |
| 31 | volatile decltype(ml) mlv = ml; |
| 32 | lv(); // expected-error{{no matching function for call to object of type}} |
| 33 | mlv(); // expected-error{{no matching function for call to object of type}} |
| 34 | |
| 35 | bogus_override_if_virtual<decltype(l)> bogus; |
| 36 | } |
| 37 | |
| 38 | // Default arguments (8.3.6) shall not be specified in the |
| 39 | // parameter-declaration-clause of a lambda- declarator. |
| 40 | int test_default_args() { |
| 41 | return [](int i = 5, // expected-error{{default arguments can only be specified for parameters in a function declaration}} |
| 42 | int j = 17) { return i+j;}(5, 6); // expected-error{{default arguments can only be specified for parameters in a function declaration}} |
| 43 | } |
| 44 | |
| 45 | // Any exception-specification specified on a lambda-expression |
| 46 | // applies to the corresponding function call operator. |
| 47 | void test_exception_spec() { |
| 48 | auto tl1 = []() throw(int) {}; |
| 49 | auto tl2 = []() {}; |
| 50 | static_assert(!noexcept(tl1()), "lambda can throw"); |
| 51 | static_assert(!noexcept(tl2()), "lambda can throw"); |
| 52 | |
| 53 | auto ntl1 = []() throw() {}; |
| 54 | auto ntl2 = []() noexcept(true) {}; |
| 55 | auto ntl3 = []() noexcept {}; |
| 56 | static_assert(noexcept(ntl1()), "lambda cannot throw"); |
| 57 | static_assert(noexcept(ntl2()), "lambda cannot throw"); |
| 58 | static_assert(noexcept(ntl3()), "lambda cannot throw"); |
| 59 | } |
| 60 | |