return new PathDiagnosticEventPiece(Pos, OS.str(), true, nullptr);
}
+static bool hasDefinition(const ObjCObjectPointerType *ObjPtr) {
+ const ObjCInterfaceDecl *Decl = ObjPtr->getInterfaceDecl();
+ if (!Decl)
+ return false;
+
+ return Decl->getDefinition();
+}
+
// TODO: consider checking explicit casts?
void DynamicTypeChecker::checkPostStmt(const ImplicitCastExpr *CE,
CheckerContext &C) const {
if (!DynObjCType || !StaticObjCType)
return;
+ if (!hasDefinition(DynObjCType) || !hasDefinition(StaticObjCType))
+ return;
+
ASTContext &ASTCtxt = C.getASTContext();
// Strip kindeofness to correctly detect subtyping relationships.
@interface NSNumber : NSObject <NSCopying>
@end
+@class MyType;
+
void testTypeCheck(NSString* str) {
id obj = str;
NSNumber *num = obj; // expected-warning {{}}
(void)num;
}
+
+void testForwardDeclarations(NSString* str) {
+ id obj = str;
+ // Do not warn, since no information is available wether MyType is a sub or
+ // super class of any other type.
+ MyType *num = obj; // no warning
+ (void)num;
+}