Douglas Gregor | 21f4692 | 2012-02-08 20:17:14 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify |
| 2 | |
| 3 | // Check that analysis-based warnings work in lambda bodies. |
| 4 | void analysis_based_warnings() { |
Douglas Gregor | cf11eb7 | 2012-02-15 16:20:15 +0000 | [diff] [blame] | 5 | (void)[]() -> int { }; // expected-warning{{control reaches end of non-void lambda}} |
Douglas Gregor | 21f4692 | 2012-02-08 20:17:14 +0000 | [diff] [blame] | 6 | } |
| 7 | |
Douglas Gregor | 8390afd | 2012-02-08 21:19:04 +0000 | [diff] [blame] | 8 | // Check that we get the right types of captured variables (the |
| 9 | // semantic-analysis part of p7). |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 10 | int &check_const_int(int&); |
| 11 | float &check_const_int(const int&); |
| 12 | |
| 13 | void test_capture_constness(int i, const int ic) { |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 14 | (void)[i,ic] ()->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 15 | float &fr1 = check_const_int(i); |
| 16 | float &fr2 = check_const_int(ic); |
| 17 | }; |
| 18 | |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 19 | (void)[=] ()->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 20 | float &fr1 = check_const_int(i); |
| 21 | float &fr2 = check_const_int(ic); |
| 22 | }; |
| 23 | |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 24 | (void)[i,ic] () mutable ->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 25 | int &ir = check_const_int(i); |
| 26 | float &fr = check_const_int(ic); |
| 27 | }; |
| 28 | |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 29 | (void)[=] () mutable ->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 30 | int &ir = check_const_int(i); |
| 31 | float &fr = check_const_int(ic); |
| 32 | }; |
| 33 | |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 34 | (void)[&i,&ic] ()->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 35 | int &ir = check_const_int(i); |
| 36 | float &fr = check_const_int(ic); |
| 37 | }; |
| 38 | |
Douglas Gregor | 656bc62 | 2012-02-09 08:26:42 +0000 | [diff] [blame] | 39 | (void)[&] ()->void { |
Douglas Gregor | c70fe35 | 2012-02-08 20:56:50 +0000 | [diff] [blame] | 40 | int &ir = check_const_int(i); |
| 41 | float &fr = check_const_int(ic); |
| 42 | }; |
| 43 | } |
Douglas Gregor | 21f4692 | 2012-02-08 20:17:14 +0000 | [diff] [blame] | 44 | |
| 45 | |
Douglas Gregor | 04bbab5 | 2012-02-10 16:13:20 +0000 | [diff] [blame] | 46 | struct S1 { |
| 47 | int x, y; |
Douglas Gregor | 1a22d28 | 2012-02-12 17:34:23 +0000 | [diff] [blame] | 48 | S1 &operator=(int*); |
Douglas Gregor | 04bbab5 | 2012-02-10 16:13:20 +0000 | [diff] [blame] | 49 | int operator()(int); |
| 50 | void f() { |
| 51 | [&]()->int { |
Douglas Gregor | 1a22d28 | 2012-02-12 17:34:23 +0000 | [diff] [blame] | 52 | S1 &s1 = operator=(&this->x); |
Douglas Gregor | 04bbab5 | 2012-02-10 16:13:20 +0000 | [diff] [blame] | 53 | return operator()(this->x + y); |
| 54 | }(); |
| 55 | } |
| 56 | }; |