aboutsummaryrefslogtreecommitdiff
path: root/test/Sema/block-misc.c
blob: 8349985ceb5afb467ac6e7fcd6a02b639b6e8019 (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
73
74
75
76
77
78
79
// RUN: clang -fsyntax-only -verify %s -fblocks
void donotwarn();

int (^IFP) ();
int (^II) (int);
int test1() {
	int (^PFR) (int) = 0;	// OK
	PFR = II;	// OK

	if (PFR == II)	// OK
	  donotwarn();

	if (PFR == IFP) // expected-error {{comparison of distinct block types}}
	  donotwarn();

	if (PFR == (int (^) (int))IFP) // OK
	  donotwarn();

	if (PFR == 0) // OK
	  donotwarn();

	if (PFR)	// OK
	  donotwarn();

	if (!PFR)	// OK
	  donotwarn();

	return PFR != IFP;	// expected-error {{comparison of distinct block types}}
}

int test2(double (^S)()) {
   double (^I)(int)  = (void*) S;
   (void*)I = (void *)S; 	// expected-error {{assignment to cast is illegal, lvalue casts are not supported}}

   void *pv = I;

   pv = S;		

   I(1);
 
   return (void*)I == (void *)S;
}

int^ x; // expected-error {{block pointer to non-function type is invalid}}
int^^ x1; // expected-error {{block pointer to non-function type is invalid}}

int test3() {
	char *^ y; // expected-error {{block pointer to non-function type is invalid}}
}



enum {NSBIRLazilyAllocated = 0};

int test4(int argc) {  // rdar://6251437
  ^{
    switch (argc) {
      case NSBIRLazilyAllocated:  // is an integer constant expression.
      default:
        break;
    }
  }();
  return 0;
}


// rdar://6257721 - reference to static/global is byref by default.
static int test5g;
void test5() {
  bar(^{ test5g = 1; });
}

// rdar://6405429 - __func__ in a block refers to the containing function name.
const char*test6() {
    return ^{
        return __func__;
    } ();
}