2012-02-10 02:19:44 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify
|
2012-02-02 01:18:19 +08:00
|
|
|
|
2012-02-10 02:19:44 +08:00
|
|
|
// An attribute-specifier-seq in a lambda-declarator appertains to the
|
|
|
|
// type of the corresponding function call operator.
|
|
|
|
void test_attributes() {
|
2012-02-16 00:20:15 +08:00
|
|
|
auto nrl = [](int x) -> int { if (x > 0) return x; }; // expected-warning{{control may reach end of non-void lambda}}
|
|
|
|
|
2013-01-17 09:30:42 +08:00
|
|
|
// FIXME: GCC accepts the [[gnu::noreturn]] attribute here.
|
|
|
|
auto nrl2 = []() [[gnu::noreturn]] { return; }; // expected-warning{{attribute 'noreturn' ignored}}
|
2012-02-10 02:19:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
struct bogus_override_if_virtual : public T {
|
2012-02-13 01:34:23 +08:00
|
|
|
bogus_override_if_virtual() : T(*(T*)0) { }
|
2012-02-10 02:19:44 +08:00
|
|
|
int operator()() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_quals() {
|
|
|
|
// This function call operator is declared const (9.3.1) if and only
|
|
|
|
// if the lambda- expression's parameter-declaration-clause is not
|
|
|
|
// followed by mutable.
|
2012-02-10 16:36:38 +08:00
|
|
|
auto l = [=](){}; // expected-note{{method is not marked volatile}}
|
2012-02-10 02:19:44 +08:00
|
|
|
const decltype(l) lc = l;
|
|
|
|
l();
|
|
|
|
lc();
|
|
|
|
|
2012-02-10 16:36:38 +08:00
|
|
|
auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \
|
|
|
|
// expected-note{{method is not marked volatile}}
|
2012-02-10 02:19:44 +08:00
|
|
|
const decltype(ml) mlc = ml;
|
|
|
|
ml();
|
|
|
|
mlc(); // expected-error{{no matching function for call to object of type}}
|
|
|
|
|
|
|
|
// It is neither virtual nor declared volatile.
|
|
|
|
volatile decltype(l) lv = l;
|
|
|
|
volatile decltype(ml) mlv = ml;
|
|
|
|
lv(); // expected-error{{no matching function for call to object of type}}
|
|
|
|
mlv(); // expected-error{{no matching function for call to object of type}}
|
|
|
|
|
|
|
|
bogus_override_if_virtual<decltype(l)> bogus;
|
|
|
|
}
|
|
|
|
|
2013-04-18 00:25:20 +08:00
|
|
|
// Core issue 974: default arguments (8.3.6) may be specified in the
|
|
|
|
// parameter-declaration-clause of a lambda-declarator.
|
2012-02-02 01:18:19 +08:00
|
|
|
int test_default_args() {
|
2013-04-18 00:25:20 +08:00
|
|
|
return [](int i = 5, int j = 17) { return i+j;}(5, 6);
|
2012-02-10 02:19:44 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Any exception-specification specified on a lambda-expression
|
|
|
|
// applies to the corresponding function call operator.
|
|
|
|
void test_exception_spec() {
|
|
|
|
auto tl1 = []() throw(int) {};
|
|
|
|
auto tl2 = []() {};
|
|
|
|
static_assert(!noexcept(tl1()), "lambda can throw");
|
|
|
|
static_assert(!noexcept(tl2()), "lambda can throw");
|
|
|
|
|
|
|
|
auto ntl1 = []() throw() {};
|
|
|
|
auto ntl2 = []() noexcept(true) {};
|
|
|
|
auto ntl3 = []() noexcept {};
|
|
|
|
static_assert(noexcept(ntl1()), "lambda cannot throw");
|
|
|
|
static_assert(noexcept(ntl2()), "lambda cannot throw");
|
|
|
|
static_assert(noexcept(ntl3()), "lambda cannot throw");
|
2012-02-02 01:18:19 +08:00
|
|
|
}
|
2012-02-10 02:19:44 +08:00
|
|
|
|