aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Stump <mrs@apple.com>2009-04-21 22:51:42 +0000
committerMike Stump <mrs@apple.com>2009-04-21 22:51:42 +0000
commit25efa107ae8381458ffa464c5fc7d21135bbe52d (patch)
tree2ee43ba1a3a40a8db600b7cdf736c7c0cabca231
parentc474152689a79760a38d349c665ab05a9a8d37bf (diff)
Tighten up blocks type checking. This was discussed back in the
r56595 timeframe, but left undone. Radar 6812711 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69745 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td2
-rw-r--r--lib/Sema/SemaExpr.cpp2
-rw-r--r--test/Sema/block-call.c8
-rw-r--r--test/Sema/block-misc.c12
-rw-r--r--test/Sema/block-return.c8
-rw-r--r--test/SemaObjC/blocks.m4
6 files changed, 22 insertions, 14 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 20fa1e8541..7c49cfbd67 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1242,7 +1242,7 @@ def err_int_to_block_pointer : Error<
"invalid conversion %2 integer %1, expected block pointer %0">;
def err_typecheck_comparison_of_distinct_blocks : Error<
"comparison of distinct block types (%0 and %1)">;
-def ext_typecheck_convert_incompatible_block_pointer : ExtWarn<
+def err_typecheck_convert_incompatible_block_pointer : Error<
"incompatible block pointer types %2 %1, expected %0">;
def err_typecheck_array_not_modifiable_lvalue : Error<
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index fa857575c5..81bac6631c 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4894,7 +4894,7 @@ bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy,
DiagKind = diag::err_int_to_block_pointer;
break;
case IncompatibleBlockPointer:
- DiagKind = diag::ext_typecheck_convert_incompatible_block_pointer;
+ DiagKind = diag::err_typecheck_convert_incompatible_block_pointer;
break;
case IncompatibleObjCQualifiedId:
// FIXME: Diagnose the problem in ObjCQualifiedIdTypesAreCompatible, since
diff --git a/test/Sema/block-call.c b/test/Sema/block-call.c
index 34de8b611d..9d3ff71e21 100644
--- a/test/Sema/block-call.c
+++ b/test/Sema/block-call.c
@@ -7,13 +7,13 @@ int main() {
int (*FPL) (int) = FP; // C doesn't consider this an error.
// For Blocks, the ASTContext::typesAreBlockCompatible() makes sure this is an error.
- int (^PFR) (int) = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int (^)(int)'}}
+ int (^PFR) (int) = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int (^)(int)'}}
PFR = II; // OK
int (^IFP) () = PFR;
- const int (^CIC) () = IFP; // expected-warning {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
+ const int (^CIC) () = IFP; // expected-error {{incompatible block pointer types initializing 'int (^)()', expected 'int const (^)()'}}
const int (^CICC) () = CIC;
@@ -22,7 +22,7 @@ int main() {
int * const (^IPCC1) () = IPCC;
- int * (^IPCC2) () = IPCC; // expected-warning {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
+ int * (^IPCC2) () = IPCC; // expected-error {{incompatible block pointer types initializing 'int *const (^)()', expected 'int *(^)()'}}
int (^IPCC3) (const int) = PFR;
@@ -32,7 +32,7 @@ int main() {
int (^IPCC5) (int, char (^CArg) (double)) = IPCC4;
- int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-warning {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
+ int (^IPCC6) (int, char (^CArg) (float)) = IPCC4; // expected-error {{incompatible block pointer types initializing 'int (^)(int, char (^)(double))', expected 'int (^)(int, char (^)(float))'}}
IPCC2 = 0;
IPCC2 = 1; // expected-error {{invalid conversion assigning integer 'int', expected block pointer 'int *(^)()'}}
diff --git a/test/Sema/block-misc.c b/test/Sema/block-misc.c
index bef2662bbc..dbcc253c58 100644
--- a/test/Sema/block-misc.c
+++ b/test/Sema/block-misc.c
@@ -112,13 +112,16 @@ void test11(int i) {
^{ break; }(); // expected-error {{'break' statement not in loop or switch statement}}
}
+enum { LESS };
+
+void foo(long (^comp)()) {
+}
void (^test12f)(void);
void test12() {
- test12f = ^test12f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
+ foo(^{ return LESS; }); // expected-error {{incompatible block pointer types passing 'int (^)(void)', expected 'long (^)()'}}
}
-
// rdar://6808730
void *test13 = ^{
int X = 32;
@@ -138,3 +141,8 @@ void test14() {
};
};
}
+
+void (^test90f)(void);
+void test90() {
+ test90f = ^test90f; // expected-error {{type name requires a specifier or qualifier}} expected-error {{expected expression}}
+}
diff --git a/test/Sema/block-return.c b/test/Sema/block-return.c
index 3eee002b60..e6101d176f 100644
--- a/test/Sema/block-return.c
+++ b/test/Sema/block-return.c
@@ -4,7 +4,7 @@ typedef void (^CL)(void);
CL foo() {
short y;
- short (^add1)(void) = ^{ return y+1; }; // expected-warning {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}}
+ short (^add1)(void) = ^{ return y+1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(void)', expected 'short (^)(void)'}}
CL X = ^{
if (2)
@@ -26,7 +26,7 @@ CL foo() {
return (char*)0;
};
- double (^A)(void) = ^ { // expected-warning {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}}
+ double (^A)(void) = ^ { // expected-error {{incompatible block pointer types initializing 'float (^)(void)', expected 'double (^)(void)'}}
if (1)
return (float)1.0;
else
@@ -41,7 +41,7 @@ CL foo() {
return 2; // expected-warning {{incompatible integer to pointer conversion returning 'int', expected 'char *'}}
};
- return ^{ return 1; }; // expected-warning {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}}
+ return ^{ return 1; }; // expected-error {{incompatible block pointer types returning 'int (^)(void)', expected 'CL'}}
}
typedef int (^CL2)(void);
@@ -77,7 +77,7 @@ static int funk(char *s) {
return 0;
}
void foo4() {
- int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-warning {{incompatible block pointer types initializing 'int (^)(char *)', expected 'int (^)(char const *)'}}
+ int (^xx)(const char *s) = ^(char *s) { return 1; }; // expected-error {{incompatible block pointer types initializing 'int (^)(char *)', expected 'int (^)(char const *)'}}
int (*yy)(const char *s) = funk; // expected-warning {{incompatible pointer types initializing 'int (char *)', expected 'int (*)(char const *)'}}
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 *, ...)'}} \
diff --git a/test/SemaObjC/blocks.m b/test/SemaObjC/blocks.m
index 544eddd507..baadbde3e0 100644
--- a/test/SemaObjC/blocks.m
+++ b/test/SemaObjC/blocks.m
@@ -23,12 +23,12 @@ void foo4(id (^objectCreationBlock)(int)) {
void bar5(id(^)(void));
void foo5(id (^objectCreationBlock)(int)) {
- return bar5(objectCreationBlock); // expected-warning{{incompatible block pointer types passing 'id (^)(int)', expected 'id (^)(void)'}}
+ return bar5(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)(int)', expected 'id (^)(void)'}}
}
void bar6(id(^)(int));
void foo6(id (^objectCreationBlock)()) {
- return bar6(objectCreationBlock); // expected-warning{{incompatible block pointer types passing 'id (^)()', expected 'id (^)(int)'}}
+ return bar6(objectCreationBlock); // expected-error {{incompatible block pointer types passing 'id (^)()', expected 'id (^)(int)'}}
}
void foo7(id (^x)(int)) {