summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaCXX/cxx1z-lambda-star-this.cpp
blob: 1163722081a7ec08ee46cf5563b4c6f6b5e726a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -emit-llvm-only %s
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions %s -DMS_EXTENSIONS
// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS -DDELAYED_TEMPLATE_PARSING


namespace test_star_this {
namespace ns1 {
class A {
  int x = 345;
  auto foo() {
    (void) [*this, this] { };  //expected-error{{'this' can appear only once}}
    (void) [this] { ++x; };
    (void) [*this] { ++x; };  //expected-error{{read-only variable}}
    (void) [*this] () mutable { ++x; };
    (void) [=] { return x; };
    (void) [&, this] { return x; };
    (void) [=, *this] { return x; };
    (void) [&, *this] { return x; };
  }
};
} // end ns1

namespace ns2 {
  class B {
    B(const B&) = delete; //expected-note{{deleted here}}
    int *x = (int *) 456;
    void foo() {
      (void)[this] { return x; };
      (void)[*this] { return x; }; //expected-error{{call to deleted}}
    }
  };
} // end ns2
namespace ns3 {
  class B {
    B(const B&) = delete; //expected-note2{{deleted here}}
    
    int *x = (int *) 456;
    public: 
    template<class T = int>
    void foo() {
      (void)[this] { return x; };
      (void)[*this] { return x; }; //expected-error2{{call to deleted}}
    }
    
    B() = default;
  } b;
  B *c = (b.foo(), nullptr); //expected-note{{in instantiation}}
} // end ns3

namespace ns4 {
template<class U>
class B {
  B(const B&) = delete; //expected-note{{deleted here}}
  double d = 3.14;
  public: 
  template<class T = int>
  auto foo() {
    const auto &L = [*this] (auto a) mutable { //expected-error{{call to deleted}}
      d += a; 
      return [this] (auto b) { return d +=b; }; 
    }; 
  }
  
  B() = default;
};
void main() {
  B<int*> b;
  b.foo(); //expected-note{{in instantiation}}
} // end main  
} // end ns4
} //end ns test_star_this
OpenPOWER on IntegriCloud