blob: 9dbe2e189f4af50f40c0576baf088dc21369e0ca [file] [log] [blame]
Douglas Gregor21f46922012-02-08 20:17:14 +00001// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2
3// Check that analysis-based warnings work in lambda bodies.
4void analysis_based_warnings() {
Douglas Gregorcf11eb72012-02-15 16:20:15 +00005 (void)[]() -> int { }; // expected-warning{{control reaches end of non-void lambda}}
Douglas Gregor21f46922012-02-08 20:17:14 +00006}
7
Douglas Gregor8390afd2012-02-08 21:19:04 +00008// Check that we get the right types of captured variables (the
9// semantic-analysis part of p7).
Douglas Gregorc70fe352012-02-08 20:56:50 +000010int &check_const_int(int&);
11float &check_const_int(const int&);
12
13void test_capture_constness(int i, const int ic) {
Douglas Gregor656bc622012-02-09 08:26:42 +000014 (void)[i,ic] ()->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000015 float &fr1 = check_const_int(i);
16 float &fr2 = check_const_int(ic);
17 };
18
Douglas Gregor656bc622012-02-09 08:26:42 +000019 (void)[=] ()->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000020 float &fr1 = check_const_int(i);
21 float &fr2 = check_const_int(ic);
22 };
23
Douglas Gregor656bc622012-02-09 08:26:42 +000024 (void)[i,ic] () mutable ->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000025 int &ir = check_const_int(i);
26 float &fr = check_const_int(ic);
27 };
28
Douglas Gregor656bc622012-02-09 08:26:42 +000029 (void)[=] () mutable ->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000030 int &ir = check_const_int(i);
31 float &fr = check_const_int(ic);
32 };
33
Douglas Gregor656bc622012-02-09 08:26:42 +000034 (void)[&i,&ic] ()->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000035 int &ir = check_const_int(i);
36 float &fr = check_const_int(ic);
37 };
38
Douglas Gregor656bc622012-02-09 08:26:42 +000039 (void)[&] ()->void {
Douglas Gregorc70fe352012-02-08 20:56:50 +000040 int &ir = check_const_int(i);
41 float &fr = check_const_int(ic);
42 };
43}
Douglas Gregor21f46922012-02-08 20:17:14 +000044
45
Douglas Gregor04bbab52012-02-10 16:13:20 +000046struct S1 {
47 int x, y;
Douglas Gregor1a22d282012-02-12 17:34:23 +000048 S1 &operator=(int*);
Douglas Gregor04bbab52012-02-10 16:13:20 +000049 int operator()(int);
50 void f() {
51 [&]()->int {
Douglas Gregor1a22d282012-02-12 17:34:23 +000052 S1 &s1 = operator=(&this->x);
Douglas Gregor04bbab52012-02-10 16:13:20 +000053 return operator()(this->x + y);
54 }();
55 }
56};