summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.def2
-rw-r--r--clang/lib/Sema/SemaStmt.cpp10
-rw-r--r--clang/test/SemaObjC/catch-stmt.m10
3 files changed, 20 insertions, 2 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.def b/clang/include/clang/Basic/DiagnosticSemaKinds.def
index 4138436a88e..c02ee6e538c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.def
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.def
@@ -960,6 +960,8 @@ DIAG(error_rethrow_used_outside_catch, ERROR,
"@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
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 49bd85a9e7e..7e7edbe51ad 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -965,9 +965,15 @@ Sema::ActOnObjCAtCatchStmt(SourceLocation AtLoc,
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);
}
diff --git a/clang/test/SemaObjC/catch-stmt.m b/clang/test/SemaObjC/catch-stmt.m
new file mode 100644
index 00000000000..9aa6e057f4f
--- /dev/null
+++ b/clang/test/SemaObjC/catch-stmt.m
@@ -0,0 +1,10 @@
+// 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}}
+ }
+}
+
OpenPOWER on IntegriCloud