blob: 74003431c683f94381971c741f1a68a62b38a10f [file] [log] [blame]
Douglas Gregora30a0bc2012-02-09 18:19:44 +00001// RUN: %clang_cc1 -std=c++11 %s -Winvalid-noreturn -verify
Douglas Gregor6b8ef342012-02-01 17:18:19 +00002
Douglas Gregora30a0bc2012-02-09 18:19:44 +00003// An attribute-specifier-seq in a lambda-declarator appertains to the
4// type of the corresponding function call operator.
5void test_attributes() {
6 auto nrl = []() [[noreturn]] {}; // expected-warning{{function declared 'noreturn' should not return}}
Douglas Gregor6b8ef342012-02-01 17:18:19 +00007}
Douglas Gregora30a0bc2012-02-09 18:19:44 +00008
9template<typename T>
10struct bogus_override_if_virtual : public T {
11 int operator()() const;
12};
13
14void 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.
Douglas Gregor12695102012-02-10 08:36:38 +000018 auto l = [=](){}; // expected-note{{method is not marked volatile}}
Douglas Gregora30a0bc2012-02-09 18:19:44 +000019 const decltype(l) lc = l;
20 l();
21 lc();
22
Douglas Gregor12695102012-02-10 08:36:38 +000023 auto ml = [=]() mutable{}; // expected-note{{method is not marked const}} \
24 // expected-note{{method is not marked volatile}}
Douglas Gregora30a0bc2012-02-09 18:19:44 +000025 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.
40int 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.
47void 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