]> granicus.if.org Git - clang/commitdiff
Make casting 'super' a deprecated warning (instead of a hard error).
authorSteve Naroff <snaroff@apple.com>
Mon, 6 Apr 2009 22:07:54 +0000 (22:07 +0000)
committerSteve Naroff <snaroff@apple.com>
Mon, 6 Apr 2009 22:07:54 +0000 (22:07 +0000)
This will simplify clang adoption, and is probably better "etiquette" (since gcc has always accepted this idiom without warning). Once we are over the adoption hurdle, we can turn this into an error.

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/SemaObjC/call-super-2.m

index 1bdabadf4509da16ef2e5682c04330e20b5507c6..b51162ae941b284f9cdc3a7770258fdfe6a38e8a 100644 (file)
@@ -1020,8 +1020,8 @@ def err_catch_param_not_objc_type : Error<
   "@catch parameter is not an Objective-C class type">;
 def err_illegal_qualifiers_on_catch_parm : Error<
   "illegal qualifiers on @catch parameter">;
-def err_illegal_super_cast : Error<
-  "cannot cast 'super' (it isn't an expression)">;
+def warn_super_cast_deprecated : Warning<
+  "casting 'super' is deprecated (it isn't an expression)">;
 
 
 // C++ casts
index e836a58432fbe1bb869457f455b0d1a17f72b397..f348f86498469eb8a0d01632c3383069312909d5 100644 (file)
@@ -2500,7 +2500,7 @@ bool Sema::CheckCastTypes(SourceRange TyR, QualType castType, Expr *&castExpr) {
     if (CheckVectorCast(TyR, castType, castExpr->getType()))
       return true;
   } else if (getLangOptions().ObjC1 && isa<ObjCSuperExpr>(castExpr)) {
-    return Diag(castExpr->getLocStart(), diag::err_illegal_super_cast) << TyR;
+    Diag(castExpr->getLocStart(), diag::warn_super_cast_deprecated) << TyR;
   }
   return false;
 }
index 6b1804b3e20c1fc43f707e4951ae6982a2fab358..cc66cf3f219283220b1fa87b91cd8dcc071f8474 100644 (file)
@@ -2,7 +2,10 @@
 
 #include <stddef.h>
 
-typedef struct objc_object *id;
+typedef struct objc_class *Class;
+typedef struct objc_object {
+    Class isa;
+} *id;
 id objc_getClass(const char *s);
 
 @interface Object 
@@ -39,17 +42,17 @@ id objc_getClass(const char *s);
 + (int) class_func2
 {
    int i = [(id <Func>)self class_func0];  // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion initializing 'id', expected 'int'}}
-   i += [(id <Func>)super class_func0];    // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   i += [(id <Func>)super class_func0];    // expected-warning {{casting 'super' is deprecated (it isn't an expression)}} // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion assigning 'id', expected 'int'}}
    i += [(Class <Func>)self class_func0];  // expected-error {{protocol qualified 'Class' is unsupported}}
-   return i + [(Class <Func>)super class_func0]; // expected-error {{protocol qualified 'Class' is unsupported}} // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return i + [(Class <Func>)super class_func0]; // expected-error {{protocol qualified 'Class' is unsupported}} // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
 }
 + (int) class_func3
 {
-   return [(Object <Func> *)super class_func0];  // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return [(Object <Func> *)super class_func0];  // expected-warning {{casting 'super' is deprecated (it isn't an expression)}} // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion returning 'id', expected 'int'}}
 }
 + (int) class_func4
 {
-   return [(Derived <Func> *)super class_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return [(Derived <Func> *)super class_func0]; // expected-warning {{casting 'super' is deprecated (it isn't an expression)}} // expected-warning {{method '-class_func0' not found (return type defaults to 'id')}} // expected-warning {{incompatible pointer to integer conversion returning 'id', expected 'int'}}
 }   
 + (int) class_func5
 {
@@ -71,15 +74,15 @@ id objc_getClass(const char *s);
 }
 - (int) instance_func2
 {
-   return [(id <Func>)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return [(id <Func>)super instance_func0]; // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
 }
 - (int) instance_func3
 {
-   return [(Object <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return [(Object <Func> *)super instance_func0]; // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
 }
 - (int) instance_func4
 {
-   return [(Derived <Func> *)super instance_func0]; // expected-error {{cannot cast 'super' (it isn't an expression)}}
+   return [(Derived <Func> *)super instance_func0]; // expected-warning {{casting 'super' is deprecated (it isn't an expression)}}
 }   
 - (int) instance_func5
 {