aboutsummaryrefslogtreecommitdiff
path: root/SingleSource/UnitTests/block-byref-cxxobj-test.cpp
blob: 42c63186d067257d68d3a03015310a38aa4addde (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
// rdar://8594790
#if defined(__BLOCKS__) && defined(__clang__)
#include <Block.h>
extern "C" void abort();
static int count=0;
class A {
public:
        int x;
        A(const A &o) { ++count; x = o.x; 
	  if (this == &o)
            abort();
        }
        A &operator =(const A &o) { x = o.x; return *this; }
        A() : x(100) { ++count; }
        ~A();
        void hello() const { 
          if (x != 100) 
            abort();
        }
};

A::~A() { 
  --count; 
  if (x != 100)
    abort();
  x = 0; 
}
#endif

int
main()
{
#if defined(__BLOCKS__) && defined(__clang__)
  if (!count) {
        __block A a;
        A ca;
        void (^b)(void) = Block_copy(^{ a.hello(); ca.hello(); });
        b();
        Block_release(b);
  }
  if (count)
    abort();
#endif
  return 0;
}