]> granicus.if.org Git - clang/commitdiff
Fix <rdar://problem/6632061> [sema] non object types should not be allowed in @catch...
authorSteve Naroff <snaroff@apple.com>
Tue, 3 Mar 2009 20:59:06 +0000 (20:59 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 3 Mar 2009 20:59:06 +0000 (20:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65968 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.def
lib/Sema/SemaStmt.cpp
test/SemaObjC/catch-stmt.m [new file with mode: 0644]

index 4138436a88ebe4993165f0ff7c58ed96c5267135..c02ee6e538ce3e77f15c6e265ad07d76824d2d35 100644 (file)
@@ -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
index 49bd85a9e7e2bb2696e87e140123eb20a13d0e80..7e7edbe51ad10861ef6ee6e7a711834c41ec9196 100644 (file)
@@ -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/test/SemaObjC/catch-stmt.m b/test/SemaObjC/catch-stmt.m
new file mode 100644 (file)
index 0000000..9aa6e05
--- /dev/null
@@ -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}}
+  }
+}
+