64 lines · cpp
1// RUN: %clang_cc1 -Werror=return-type -std=c++11 %s -Winvalid-noreturn -verify2 3// An attribute-specifier-seq in a lambda-declarator appertains to the4// type of the corresponding function call operator.5void test_attributes() {6 auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-error{{non-void lambda does not return a value in all control paths}}7 8 // FIXME: GCC accepts the [[gnu::noreturn]] attribute here.9 auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'gnu::noreturn' ignored}}10}11 12template<typename T>13struct bogus_override_if_virtual : public T {14 bogus_override_if_virtual() : T(*(T*)0) { } // expected-warning {{binding dereferenced null pointer to reference has undefined behavior}}15 int operator()() const;16};17 18void test_quals() {19 // This function call operator is declared const (9.3.1) if and only20 // if the lambda- expression's parameter-declaration-clause is not21 // followed by mutable.22 auto l = [=](){}; // expected-note{{method is not marked volatile}}23 const decltype(l) lc = l;24 l();25 lc();26 27 auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \28 // expected-note{{method is not marked volatile}} 29 const decltype(ml) mlc = ml;30 ml();31 mlc(); // expected-error{{no matching function for call to object of type}}32 33 // It is neither virtual nor declared volatile.34 volatile decltype(l) lv = l;35 volatile decltype(ml) mlv = ml;36 lv(); // expected-error{{no matching function for call to object of type}}37 mlv(); // expected-error{{no matching function for call to object of type}}38 39 bogus_override_if_virtual<decltype(l)> bogus; // expected-note{{in instantiation of member function 'bogus_override_if_virtual<(lambda}}40}41 42// Core issue 974: default arguments (8.3.6) may be specified in the43// parameter-declaration-clause of a lambda-declarator.44int test_default_args() {45 return [](int i = 5, int j = 17) { return i+j;}(5, 6);46}47 48// Any exception-specification specified on a lambda-expression49// applies to the corresponding function call operator.50void test_exception_spec() {51 auto tl1 = []() throw(int) {};52 auto tl2 = []() {};53 static_assert(!noexcept(tl1()), "lambda can throw");54 static_assert(!noexcept(tl2()), "lambda can throw");55 56 auto ntl1 = []() throw() {};57 auto ntl2 = []() noexcept(true) {};58 auto ntl3 = []() noexcept {};59 static_assert(noexcept(ntl1()), "lambda cannot throw"); 60 static_assert(noexcept(ntl2()), "lambda cannot throw"); 61 static_assert(noexcept(ntl3()), "lambda cannot throw"); 62}63 64