blob: 8fa3837214d3f2d58e00d8f6453f1909d6f6c71f [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 Gregor656bc622012-02-09 08:26:42 +00005 (void)[]() -> int { }; // expected-warning{{control reaches end of non-void function}}
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;
48 int operator()(int);
49 void f() {
50 [&]()->int {
51 return operator()(this->x + y);
52 }();
53 }
54};