2009-12-15 23:14:24 +03:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only %s -verify -fblocks
|
2008-09-17 02:25:10 +04:00
|
|
|
|
|
|
|
typedef void (^CL)(void);
|
|
|
|
|
|
|
|
CL foo() {
|
2009-02-05 01:31:32 +03:00
|
|
|
short y;
|
2009-04-22 02:51:42 +04:00
|
|
|
short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}}
|
2008-09-17 02:25:10 +04:00
|
|
|
|
2009-02-05 01:31:32 +03:00
|
|
|
CL X = ^{
|
|
|
|
if (2)
|
|
|
|
return;
|
2008-09-17 02:25:10 +04:00
|
|
|
return 1; // expected-error {{void block should not return a value}}
|
|
|
|
};
|
2009-02-05 01:31:32 +03:00
|
|
|
|
|
|
|
int (^Y) (void) = ^{
|
2008-09-17 02:25:10 +04:00
|
|
|
if (3)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return; // expected-error {{non-void block should return a value}}
|
|
|
|
};
|
|
|
|
|
2009-02-05 01:31:32 +03:00
|
|
|
char *(^Z)(void) = ^{
|
2008-09-17 02:25:10 +04:00
|
|
|
if (3)
|
|
|
|
return "";
|
|
|
|
else
|
|
|
|
return (char*)0;
|
|
|
|
};
|
|
|
|
|
2009-04-22 02:51:42 +04:00
|
|
|
double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}}
|
2009-02-05 01:31:32 +03:00
|
|
|
if (1)
|
|
|
|
return (float)1.0;
|
2008-09-17 02:25:10 +04:00
|
|
|
else
|
|
|
|
if (2)
|
2009-09-09 19:08:12 +04:00
|
|
|
return (double)2.0;
|
2009-02-05 01:31:32 +03:00
|
|
|
return 1;
|
2008-09-17 02:25:10 +04:00
|
|
|
};
|
2009-02-05 01:31:32 +03:00
|
|
|
char *(^B)(void) = ^{
|
2008-09-17 02:25:10 +04:00
|
|
|
if (3)
|
|
|
|
return "";
|
|
|
|
else
|
2009-02-05 01:31:32 +03:00
|
|
|
return 2; // expected-warning {{incompatible integer to pointer conversion returning 'int', expected 'char *'}}
|
2008-09-17 02:25:10 +04:00
|
|
|
};
|
2009-02-05 01:31:32 +03:00
|
|
|
|
2009-04-22 02:51:42 +04:00
|
|
|
return ^{ return 1; }; // expected-error {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}}
|
2008-09-17 02:25:10 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (^CL2)(void);
|
|
|
|
|
|
|
|
CL2 foo2() {
|
2009-04-17 04:09:41 +04:00
|
|
|
return ^{ return 1; };
|
2008-09-17 02:25:10 +04:00
|
|
|
}
|
2008-09-25 02:26:48 +04:00
|
|
|
|
|
|
|
typedef unsigned int * uintptr_t;
|
|
|
|
typedef char Boolean;
|
|
|
|
typedef int CFBasicHash;
|
|
|
|
|
|
|
|
#define INVOKE_CALLBACK2(P, A, B) (P)(A, B)
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
Boolean (^isEqual)(const CFBasicHash *, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key);
|
|
|
|
} CFBasicHashCallbacks;
|
|
|
|
|
|
|
|
int foo3() {
|
|
|
|
CFBasicHashCallbacks cb;
|
|
|
|
|
|
|
|
Boolean (*value_equal)(uintptr_t, uintptr_t) = 0;
|
|
|
|
|
|
|
|
cb.isEqual = ^(const CFBasicHash *table, uintptr_t stack_value_or_key1, uintptr_t stack_value_or_key2, Boolean is_key) {
|
2009-09-09 19:08:12 +04:00
|
|
|
return (Boolean)(uintptr_t)INVOKE_CALLBACK2(value_equal, (uintptr_t)stack_value_or_key1, (uintptr_t)stack_value_or_key2);
|
2008-09-25 02:26:48 +04:00
|
|
|
};
|
|
|
|
}
|
2008-09-25 03:31:10 +04:00
|
|
|
|
|
|
|
static int funk(char *s) {
|
2008-09-28 05:11:11 +04:00
|
|
|
if (^{} == ((void*)0))
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
2008-09-25 03:31:10 +04:00
|
|
|
}
|
2010-01-09 23:43:19 +03:00
|
|
|
void next();
|
2008-09-25 03:31:10 +04:00
|
|
|
void foo4() {
|
2009-04-22 02:51:42 +04:00
|
|
|
int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(char *)', expected 'int (^)(char const *)'}}
|
2008-09-25 03:31:10 +04:00
|
|
|
int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (char *)', expected 'int (*)(char const *)'}}
|
2008-09-28 04:13:36 +04:00
|
|
|
|
2009-02-14 03:32:47 +03:00
|
|
|
int (^nested)(char *s) = ^(char *str) { void (^nest)(void) = ^(void) { printf("%s\n", str); }; next(); return 1; }; // expected-warning{{implicitly declaring C library function 'printf' with type 'int (char const *, ...)'}} \
|
|
|
|
// expected-note{{please include the header <stdio.h> or explicitly provide a declaration for 'printf'}}
|
2008-09-25 03:31:10 +04:00
|
|
|
}
|
2009-04-17 04:09:41 +04:00
|
|
|
|
|
|
|
typedef void (^bptr)(void);
|
|
|
|
|
|
|
|
bptr foo5(int j) {
|
|
|
|
__block int i;
|
|
|
|
if (j)
|
|
|
|
return ^{ ^{ i=0; }(); }; // expected-error {{returning block that lives on the local stack}}
|
|
|
|
return ^{ i=0; }; // expected-error {{returning block that lives on the local stack}}
|
2009-09-08 04:36:37 +04:00
|
|
|
return (^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
|
|
|
|
return (void*)(^{ i=0; }); // expected-error {{returning block that lives on the local stack}}
|
2009-04-17 04:09:41 +04:00
|
|
|
}
|
2009-04-28 05:10:27 +04:00
|
|
|
|
|
|
|
int (*funcptr3[5])(long);
|
|
|
|
int sz8 = sizeof(^int (*[5])(long) {return funcptr3;}); // expected-error {{block declared as returning an array}}
|
2009-04-29 23:03:13 +04:00
|
|
|
|
|
|
|
void foo6() {
|
2009-04-30 01:40:37 +04:00
|
|
|
int (^b)(int) __attribute__((noreturn));
|
2009-04-29 23:03:13 +04:00
|
|
|
b = ^ (int i) __attribute__((noreturn)) { return 1; }; // expected-error {{block declared 'noreturn' should not return}}
|
|
|
|
b(1);
|
2009-04-30 01:40:37 +04:00
|
|
|
int (^c)(void) __attribute__((noreturn)) = ^ __attribute__((noreturn)) { return 100; }; // expected-error {{block declared 'noreturn' should not return}}
|
2009-04-29 23:03:13 +04:00
|
|
|
}
|
2009-06-20 03:37:08 +04:00
|
|
|
|
|
|
|
|
|
|
|
void foo7()
|
|
|
|
{
|
|
|
|
const int (^BB) (void) = ^{ const int i = 1; return i; }; // OK
|
|
|
|
const int (^CC) (void) = ^const int{ const int i = 1; return i; }; // OK
|
|
|
|
|
|
|
|
int i;
|
|
|
|
int (^FF) (void) = ^{ return i; }; // OK
|
|
|
|
int (^EE) (void) = ^{ return i+1; }; // OK
|
|
|
|
|
|
|
|
__block int j;
|
|
|
|
int (^JJ) (void) = ^{ return j; }; // OK
|
|
|
|
int (^KK) (void) = ^{ return j+1; }; // OK
|
|
|
|
|
|
|
|
__block const int k;
|
|
|
|
const int cint = 100;
|
|
|
|
|
|
|
|
int (^MM) (void) = ^{ return k; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}}
|
|
|
|
int (^NN) (void) = ^{ return cint; }; // expected-error {{incompatible block pointer types initializing 'int const (^)(void)', expected 'int (^)(void)'}}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|