aboutsummaryrefslogtreecommitdiff
path: root/SingleSource/UnitTests/block-copied-in-cxxobj.cpp
blob: ef4662d214d7143a5deb5e39a0d6dfd2e80d3f18 (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
#if defined(__BLOCKS__) && defined(__clang__)
// rdar://8594790
#include <Block.h>

extern "C" void abort();

int count = 100;
int no=1;

struct S {
  S() { no = 0; };
  ~S() { if (no != 0) abort(); }
};

static S s1;

class A {
public:
        int x;
        A(const A &o) { ++no; x = o.x; }
        A &operator =(const A &o) { x = o.x; return *this; }
        A() : x(count++) { ++no; }
        virtual ~A() { --no; }
        void hello() const { }
};
#endif

int
main()
{
#if defined(__BLOCKS__) && defined(__clang__)
        A a;
        A a1;
        A a2;
        void (^b)(void) = ^{ a.hello(); a1.hello(); a2.hello(); };
        b();

        void (^c)(void) = Block_copy(^{ a.hello(); a1.hello(); a2.hello(); });
        c();
	if (no != 12)
	  abort();
        Block_release(c);
	if (no != 9)
	  abort();
#endif
        return 0;
}