summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-in-class.C
blob: 33f4301e44fec9e3207edc87f199c64e2dbd2b46 (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
// { dg-do run }
// { dg-options "-std=c++0x" }

#include <cassert>

class C {
  private:
    int m_i;

  public:
    C() : m_i(-1) {
      //[] { this; } ();
      [this] () -> void { m_i = 0; } ();
      assert(m_i == 0);
      [this] () -> void { this->m_i = 1; } ();
      assert(m_i == 1);
      [&] () -> void { m_i = 2; } ();
      assert(m_i == 2);
      [&] () -> void { this->m_i = 3; } ();
      assert(m_i == 3);
      [=] () -> void { m_i = 4; } (); // copies 'this' or --copies-m_i--?
      assert(m_i == 4);
      [=] () -> void { this->m_i = 5; } ();
      assert(m_i == 5);
    }

};

int main() {
  C c;

  //[this] () -> void {} (); // { dg-error: "cannot capture `this' outside of class method" }

  return 0;
}