]> granicus.if.org Git - clang/commitdiff
Tighten up blocks type checking. This was discussed back in the
authorMike Stump <mrs@apple.com>
Tue, 21 Apr 2009 22:51:42 +0000 (22:51 +0000)
committerMike Stump <mrs@apple.com>
Tue, 21 Apr 2009 22:51:42 +0000 (22:51 +0000)
r56595 timeframe, but left undone.  Radar 6812711

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69745 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/block-call.c
test/Sema/block-misc.c
test/Sema/block-return.c
test/SemaObjC/blocks.m

index 20fa1e85417e13358dcdf0d1f3aa3c4a8e397b05..7c49cfbd671456603cdb0aef15aed6b4e8a71e80 100644 (file)
@@ -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<
index fa857575c5d1ea16ae6433fd9c5a6dc5e345ecef..81bac6631cec31dbcaeb34cdf12221842ed4280c 100644 (file)
@@ -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
index 34de8b611d8aeb4f8096c2685da75d80b029de00..9d3ff71e2195ecc052aec2fd50cf689287ee0ac3 100644 (file)
@@ -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 *(^)()'}}
index bef2662bbcd8e20296ab820741c393f02ad2e784..dbcc253c58b818a0d7507ebf5b1dc6c3b18ad377 100644 (file)
@@ -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}}
+}
index 3eee002b6038a140fd56fe96d1118449fd73530e..e6101d176f895ae0b157bc972f73604f42465f40 100644 (file)
@@ -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 *, ...)'}} \
index 544eddd507d487c3d2825e42f2e63caf3a987b59..baadbde3e0408b3b491cbef7f45a870f0a3db4a0 100644 (file)
@@ -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)) {