"method %objcinstance0 not found in protocol (return type defaults to 'id')")
DIAG(error_bad_receiver_type, ERROR,
"bad receiver type %0")
+DIAG(warn_objc_throw_expects_object, WARNING,
+ "invalid %0 argument (expected an ObjC object type)")
// C++ casts
}
Action::OwningStmtResult
-Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg Throw) {
- return Owned(new (Context) ObjCAtThrowStmt(AtLoc,
- static_cast<Expr*>(Throw.release())));
+Sema::ActOnObjCAtThrowStmt(SourceLocation AtLoc, ExprArg expr) {
+ Expr *ThrowExpr = static_cast<Expr*>(expr.release());
+ if (!ThrowExpr) {
+ // FIXME: verify the 'rethrow' is within a @catch block
+ } else {
+ QualType ThrowType = ThrowExpr->getType();
+ // Make sure the expression type is an ObjC pointer or "void *".
+ if (!Context.isObjCObjectPointerType(ThrowType)) {
+ const PointerType *PT = ThrowType->getAsPointerType();
+ if (!PT || !PT->getPointeeType()->isVoidType())
+ // This should be an error, however GCC only yields a warning.
+ Diag(AtLoc, diag::warn_objc_throw_expects_object)
+ << ThrowExpr->getType() << ThrowExpr->getSourceRange();
+ }
+ }
+ return Owned(new (Context) ObjCAtThrowStmt(AtLoc, ThrowExpr));
}
Action::OwningStmtResult
// the exception name is optional (weird)
@catch (NSException *) {}
}
+@end
+
+int foo() {
+ @throw 42; // expected-warning {{invalid 'int' argument (expected an ObjC object type)}}
+ @throw; // FIXME: error: ‘@throw’ (rethrow) used outside of a @catch block
+}