"@throw (rethrow) used outside of a @catch block")
DIAG(err_attribute_multiple_objc_gc, ERROR,
"multiple garbage collection attributes specified for type")
+DIAG(err_catch_param_not_objc_type, ERROR,
+ "@catch parameter is not an Objective-C class type")
// C++ casts
SourceLocation RParen, DeclTy *Parm,
StmtArg Body, StmtArg catchList) {
Stmt *CatchList = static_cast<Stmt*>(catchList.release());
+ ParmVarDecl *PVD = static_cast<ParmVarDecl*>(Parm);
+
+ // PVD == 0 implies @catch(...).
+ if (PVD && !Context.isObjCObjectPointerType(PVD->getType()))
+ return StmtError(Diag(PVD->getLocation(),
+ diag::err_catch_param_not_objc_type));
+
ObjCAtCatchStmt *CS = new (Context) ObjCAtCatchStmt(AtLoc, RParen,
- static_cast<ParmVarDecl*>(Parm), static_cast<Stmt*>(Body.release()),
- CatchList);
+ PVD, static_cast<Stmt*>(Body.release()), CatchList);
return Owned(CatchList ? CatchList : CS);
}
--- /dev/null
+// RUN: clang -verify %s
+
+void f() {
+ @try {
+ } @catch (void a) { // expected-error{{@catch parameter is not an Objective-C class type}}
+ } @catch (int) { // expected-error{{@catch parameter is not an Objective-C class type}}
+ } @catch (int *b) { // expected-error{{@catch parameter is not an Objective-C class type}}
+ }
+}
+