1 // RUN: %clang_cc1 -triple %itanium_abi_triple -fsyntax-only -verify -fblocks -Wno-strict-prototypes %s
7 void foo(id <NSObject>(^objectCreationBlock)(void)) {
8 return bar(objectCreationBlock);
11 void bar2(id(*)(void));
12 void foo2(id <NSObject>(*objectCreationBlock)(void)) {
13 return bar2(objectCreationBlock);
17 void foo3(id (*objectCreationBlock)(int)) {
18 return bar3(objectCreationBlock);
22 void foo4(id (^objectCreationBlock)(int)) {
23 return bar4(objectCreationBlock);
26 void bar5(id(^)(void)); // expected-note 3{{passing argument to parameter here}}
27 void foo5(id (^objectCreationBlock)(bool)) {
28 bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(bool)' to parameter of type 'id (^)(void)'}}
30 bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(_Bool)' to parameter of type 'id (^)(void)'}}
32 bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(_Bool)' to parameter of type 'id (^)(void)'}}
35 void bar6(id(^)(int));
36 void foo6(id (^objectCreationBlock)()) {
37 return bar6(objectCreationBlock);
40 void foo7(id (^x)(int)) {
48 void *P = ^(itf x) {}; // expected-error {{interface type 'itf' cannot be passed by value; did you forget * in 'itf'}}
49 P = ^itf(int x) {}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}}
50 P = ^itf() {}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}}
51 P = ^itf{}; // expected-error {{interface type 'itf' cannot be returned by value; did you forget * in 'itf'}}
56 typedef void (^DVTOperationGroupScheduler)();
57 id _suboperationSchedulers;
59 for (DVTOperationGroupScheduler scheduler in _suboperationSchedulers) {
67 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
70 void(^myBlock)(void) = ^{
72 NSLog(@"%@", myBlock);
76 // In C, enum constants have the type of the underlying integer type, not the
77 // enumeration they are part of. We pretend the constants have enum type if
78 // all the returns seem to be playing along.
83 enum CStyleEnum getCSE();
84 typedef enum CStyleEnum (^cse_block_t)();
86 void testCStyleEnumInference(bool arg) {
88 enum CStyleEnum value;
91 a = ^{ return getCSE(); };
92 a = ^{ return value; };
94 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
104 a = ^{ if (arg) return CSE_Value; else return getCSE(); };
105 a = ^{ if (arg) return getCSE(); else return CSE_Value; };
106 a = ^{ if (arg) return value; else return CSE_Value; };
108 // These two blocks actually return 'int'
109 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
116 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
123 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
127 return value; // expected-error {{return type 'enum CStyleEnum' must match previous return type 'int'}}
130 extern void check_enum(void);
132 return (arg ? (CSE_Value) : (check_enum(), (!arg ? CSE_Value2 : getCSE())));
135 return (arg ? (CSE_Value) : ({check_enum(); CSE_Value2; }));
140 enum FixedTypeEnum : unsigned {
143 enum FixedTypeEnum getFTE();
144 typedef enum FixedTypeEnum (^fte_block_t)();
146 void testFixedTypeEnumInference(bool arg) {
150 a = ^{ return getFTE(); };
152 // Since we fixed the underlying type of the enum, this is considered a
153 // compatible block type.
162 a = ^{ if (arg) return FTE_Value; else return FTE_Value; };
163 a = ^{ if (arg) return getFTE(); else return getFTE(); };
164 a = ^{ if (arg) return FTE_Value; else return getFTE(); };
165 a = ^{ if (arg) return getFTE(); else return FTE_Value; };
167 // These two blocks actually return 'unsigned'.
189 FixedAnonymousValue = 1
195 TypeDefEnum getTDE();
197 typedef enum : short {
199 } TypeDefFixedTypeEnum;
200 TypeDefFixedTypeEnum getTDFTE();
202 typedef int (^int_block_t)();
203 typedef short (^short_block_t)();
204 void testAnonymousEnumTypes(int arg) {
206 IB = ^{ return AnonymousValue; };
207 IB = ^{ if (arg) return TDE_Value; else return getTDE(); };
208 IB = ^{ if (arg) return getTDE(); else return TDE_Value; };
210 // Since we fixed the underlying type of the enum, these are considered
211 // compatible block types anyway.
213 SB = ^{ return FixedAnonymousValue; };
214 SB = ^{ if (arg) return TDFTE_Value; else return getTDFTE(); };
215 SB = ^{ if (arg) return getTDFTE(); else return TDFTE_Value; };
218 static inline void inlinefunc() {
221 void inlinefunccaller() { inlinefunc(); }