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 = []() [[noreturn]] {}; // expected-warning{{function declared 'noreturn' should not return}} 7 } 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. 18 auto l = [](){}; // expected-note{{method is not marked volatile}} 19 const decltype(l) lc = l; 20 l(); 21 lc(); 22 23 auto ml = []() mutable{}; // expected-note{{method is not marked const}} \ 24 // expected-note{{method is not marked volatile}} 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 61