1a30a0bc1SDouglas Gregor // RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify 26b8ef34fSDouglas Gregor 3a30a0bc1SDouglas Gregor // An attribute-specifier-seq in a lambda-declarator appertains to the 4a30a0bc1SDouglas Gregor // type of the corresponding function call operator. test_attributes()5a30a0bc1SDouglas Gregorvoid test_attributes() { 6*1da13237SDávid Bolvanský auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{on-void lambda does not return a value in all control paths}} 7cf11eb76SDouglas Gregor 810876ef5SRichard Smith // FIXME: GCC accepts the [[gnu::noreturn]] attribute here. 910876ef5SRichard Smith auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}} 106b8ef34fSDouglas Gregor } 11a30a0bc1SDouglas Gregor 12a30a0bc1SDouglas Gregor template<typename T> 13a30a0bc1SDouglas Gregor struct bogus_override_if_virtual : public T { bogus_override_if_virtualbogus_override_if_virtual142eeddfb1SNick Lewycky bogus_override_if_virtual() : T(*(T*)0) { } // expected-warning {{binding dereferenced null pointer to reference has undefined behavior}} 15a30a0bc1SDouglas Gregor int operator()() const; 16a30a0bc1SDouglas Gregor }; 17a30a0bc1SDouglas Gregor test_quals()18a30a0bc1SDouglas Gregorvoid test_quals() { 19a30a0bc1SDouglas Gregor // This function call operator is declared const (9.3.1) if and only 20a30a0bc1SDouglas Gregor // if the lambda- expression's parameter-declaration-clause is not 21a30a0bc1SDouglas Gregor // followed by mutable. 2212695101SDouglas Gregor auto l = [=](){}; // expected-note{{method is not marked volatile}} 23a30a0bc1SDouglas Gregor const decltype(l) lc = l; 24a30a0bc1SDouglas Gregor l(); 25a30a0bc1SDouglas Gregor lc(); 26a30a0bc1SDouglas Gregor 2712695101SDouglas Gregor auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \ 28a30a0bc1SDouglas Gregor // expected-note{{method is not marked volatile}} 29a30a0bc1SDouglas Gregor const decltype(ml) mlc = ml; 30a30a0bc1SDouglas Gregor ml(); 31a30a0bc1SDouglas Gregor mlc(); // expected-error{{no matching function for call to object of type}} 32a30a0bc1SDouglas Gregor 33a30a0bc1SDouglas Gregor // It is neither virtual nor declared volatile. 34a30a0bc1SDouglas Gregor volatile decltype(l) lv = l; 35a30a0bc1SDouglas Gregor volatile decltype(ml) mlv = ml; 36a30a0bc1SDouglas Gregor lv(); // expected-error{{no matching function for call to object of type}} 37a30a0bc1SDouglas Gregor mlv(); // expected-error{{no matching function for call to object of type}} 38a30a0bc1SDouglas Gregor 392eeddfb1SNick Lewycky bogus_override_if_virtual<decltype(l)> bogus; // expected-note{{in instantiation of member function 'bogus_override_if_virtual<(lambda}} 40a30a0bc1SDouglas Gregor } 41a30a0bc1SDouglas Gregor 423cb4c630SRichard Smith // Core issue 974: default arguments (8.3.6) may be specified in the 43a30a0bc1SDouglas Gregor // parameter-declaration-clause of a lambda-declarator. test_default_args()44a30a0bc1SDouglas Gregorint test_default_args() { 453cb4c630SRichard Smith return [](int i = 5, int j = 17) { return i+j;}(5, 6); 46a30a0bc1SDouglas Gregor } 47a30a0bc1SDouglas Gregor 48a30a0bc1SDouglas Gregor // Any exception-specification specified on a lambda-expression 49a30a0bc1SDouglas Gregor // applies to the corresponding function call operator. test_exception_spec()50a30a0bc1SDouglas Gregorvoid test_exception_spec() { 51a30a0bc1SDouglas Gregor auto tl1 = []() throw(int) {}; 52a30a0bc1SDouglas Gregor auto tl2 = []() {}; 53a30a0bc1SDouglas Gregor static_assert(!noexcept(tl1()), "lambda can throw"); 54a30a0bc1SDouglas Gregor static_assert(!noexcept(tl2()), "lambda can throw"); 55a30a0bc1SDouglas Gregor 56a30a0bc1SDouglas Gregor auto ntl1 = []() throw() {}; 57a30a0bc1SDouglas Gregor auto ntl2 = []() noexcept(true) {}; 58a30a0bc1SDouglas Gregor auto ntl3 = []() noexcept {}; 59a30a0bc1SDouglas Gregor static_assert(noexcept(ntl1()), "lambda cannot throw"); 60a30a0bc1SDouglas Gregor static_assert(noexcept(ntl2()), "lambda cannot throw"); 61a30a0bc1SDouglas Gregor static_assert(noexcept(ntl3()), "lambda cannot throw"); 62a30a0bc1SDouglas Gregor } 63a30a0bc1SDouglas Gregor 64