Clang Project

clang_source_code/test/CXX/expr/expr.prim/expr.prim.lambda/p16.cpp
1// RUN: %clang_cc1 -std=c++11 %s -Wunused -Wno-unused-lambda-capture -verify
2
3
4struct X {
5  X(const X&) = delete; // expected-note 2{{explicitly marked deleted}}
6  X(X&);
7};
8
9void test_capture(X x) {
10  [x] { }(); // okay: non-const copy ctor
11
12  [x] {
13    [x] { // expected-error{{call to deleted constructor of 'X'}}
14    }();
15  }();
16
17  [x] {
18    [&x] {
19      [x] { // expected-error{{call to deleted constructor of 'const X'}}
20      }();
21    }();
22  }();
23
24  int a; 
25  [=]{ 
26    [&] { 
27      int &x = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
28      int &x2 = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
29    }(); 
30  }(); 
31
32  [=]{ 
33    [&a] { 
34      [&] { 
35        int &x = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
36        int &x2 = a;  // expected-error{{binding value of type 'const int' to reference to type 'int' drops 'const' qualifier}}
37      }();
38    }(); 
39  }(); 
40}
41