p5.cpp revision 215e4e17d00e12c38687a95502506d8f2ca3e646
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.
5void test_attributes() {
6  auto nrl = []() [[noreturn]] {}; // expected-warning{{function declared 'noreturn' should not return}}
7}
8
9template<typename T>
10struct bogus_override_if_virtual : public T {
11  bogus_override_if_virtual() : T(*(T*)0) { }
12  int operator()() const;
13};
14
15void 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.
41int test_default_args() {
42  return [](int i = 5,  // expected-error{{default arguments can only be specified for parameters in a function declaration}}
43            int j = 17) { return i+j;}(5, 6); // expected-error{{default arguments can only be specified for parameters in a function declaration}}
44}
45
46// Any exception-specification specified on a lambda-expression
47// applies to the corresponding function call operator.
48void test_exception_spec() {
49  auto tl1 = []() throw(int) {};
50  auto tl2 = []() {};
51  static_assert(!noexcept(tl1()), "lambda can throw");
52  static_assert(!noexcept(tl2()), "lambda can throw");
53
54  auto ntl1 = []() throw() {};
55  auto ntl2 = []() noexcept(true) {};
56  auto ntl3 = []() noexcept {};
57  static_assert(noexcept(ntl1()), "lambda cannot throw");
58  static_assert(noexcept(ntl2()), "lambda cannot throw");
59  static_assert(noexcept(ntl3()), "lambda cannot throw");
60}
61
62