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