From: John McCall
Due to a bug in its implementation, GCC allows implicit downcasts -(from base class to a derived class) when calling functions. Such code is -inherently unsafe, since the object might not actually be an instance -of the derived class, and is rejected by Clang. For example, given -this code:
+of Objective-C pointers (from a base class to a derived class) when +calling functions. Such code is inherently unsafe, since the object +might not actually be an instance of the derived class, and is +rejected by Clang. For example, given this code:@interface Base @end @interface Derived : Base @end -void f(Derived *); -void g(Base *base) { - f(base); +void f(Derived *p); +void g(Base *p) { + f(p); }@@ -781,11 +778,11 @@ void g(Base *base) {
downcast.mm:6:3: error: no matching function for call to 'f' - f(base); + f(p); ^ downcast.mm:4:6: note: candidate function not viable: cannot convert from superclass 'Base *' to subclass 'Derived *' for 1st argument -void f(Derived *); +void f(Derived *p); ^@@ -798,13 +795,17 @@ explicit cast: -
class
as a property nameUse of 'class' name to declare a method is allowed in objective-c++ mode to -be compatible with GCC. However, use of property dot syntax notation to call -this method is not allowed in clang++, as [I class] is a suitable syntax that -will work. So, this test will fail in clang++. +
In C and Objective-C, class
is a normal identifier and
+can be used to name fields, ivars, methods, and so on. In
+C++, class
is a keyword. For compatibility with existing
+code, Clang permits class
to be used as part of a method
+selector in Objective-C++, but this does not extend to any other part
+of the language. In particular, it is impossible to use property dot
+syntax in Objective-C++ with the property name class
, so
+the following code will fail to parse:
@interface I { @@ -818,6 +819,7 @@ int cls; @end+Use explicit message-send syntax instead, i.e.
[I class]
.