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) {
68 extern void NSLog(NSString *format, ...) __attribute__((format(__NSString__, 1, 2)));
71 void(^myBlock)(void) = ^{
73 NSLog(@"%@", myBlock);
77 // In C, enum constants have the type of the underlying integer type, not the
78 // enumeration they are part of. We pretend the constants have enum type if
79 // all the returns seem to be playing along.
84 enum CStyleEnum getCSE();
85 typedef enum CStyleEnum (^cse_block_t)();
87 void testCStyleEnumInference(bool arg) {
89 enum CStyleEnum value;
92 a = ^{ return getCSE(); };
93 a = ^{ return value; };
95 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
105 a = ^{ if (arg) return CSE_Value; else return getCSE(); };
106 a = ^{ if (arg) return getCSE(); else return CSE_Value; };
107 a = ^{ if (arg) return value; else return CSE_Value; };
109 // These two blocks actually return 'int'
110 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
117 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
124 a = ^{ // expected-error {{incompatible block pointer types assigning to 'cse_block_t' (aka 'enum CStyleEnum (^)()') from 'int (^)(void)'}}
128 return value; // expected-error {{return type 'enum CStyleEnum' must match previous return type 'int'}}
132 extern void check_enum(void);
134 return (arg ? (CSE_Value) : (check_enum(), (!arg ? CSE_Value2 : getCSE())));
137 return (arg ? (CSE_Value) : ({check_enum(); CSE_Value2; }));
142 enum FixedTypeEnum : unsigned {
145 enum FixedTypeEnum getFTE();
146 typedef enum FixedTypeEnum (^fte_block_t)();
148 void testFixedTypeEnumInference(bool arg) {
152 a = ^{ return getFTE(); };
154 // Since we fixed the underlying type of the enum, this is considered a
155 // compatible block type.
164 a = ^{ if (arg) return FTE_Value; else return FTE_Value; };
165 a = ^{ if (arg) return getFTE(); else return getFTE(); };
166 a = ^{ if (arg) return FTE_Value; else return getFTE(); };
167 a = ^{ if (arg) return getFTE(); else return FTE_Value; };
169 // These two blocks actually return 'unsigned'.
191 FixedAnonymousValue = 1
197 TypeDefEnum getTDE();
199 typedef enum : short {
201 } TypeDefFixedTypeEnum;
202 TypeDefFixedTypeEnum getTDFTE();
204 typedef int (^int_block_t)();
205 typedef short (^short_block_t)();
206 void testAnonymousEnumTypes(int arg) {
208 IB = ^{ return AnonymousValue; };
209 IB = ^{ if (arg) return TDE_Value; else return getTDE(); };
210 IB = ^{ if (arg) return getTDE(); else return TDE_Value; };
212 // Since we fixed the underlying type of the enum, these are considered
213 // compatible block types anyway.
215 SB = ^{ return FixedAnonymousValue; };
216 SB = ^{ if (arg) return TDFTE_Value; else return getTDFTE(); };
217 SB = ^{ if (arg) return getTDFTE(); else return TDFTE_Value; };
220 static inline void inlinefunc() {
223 void inlinefunccaller() { inlinefunc(); }