]> granicus.if.org Git - clang/commitdiff
diagnose attempts to return objc interfaces by-value from C functions.
authorChris Lattner <sabre@nondot.org>
Sat, 11 Apr 2009 19:17:25 +0000 (19:17 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 11 Apr 2009 19:17:25 +0000 (19:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68873 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaObjC/blocks.m
test/SemaObjC/invalid-objc-decls-1.m
test/SemaObjC/method-bad-param.m

index 5fe44d30893a692057515732a439329ba403b901..d3f24cae90d702e2b3d2c42efbb7e0a14212c466 100644 (file)
@@ -1891,7 +1891,15 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC,
                              R->getAsFunctionType()->getResultType(),
                              diag::err_abstract_type_in_decl, 
                              AbstractReturnType))
-        InvalidDecl = true;
+    InvalidDecl = true;
+  
+  // Do not allow returning a objc interface by-value.
+  if (R->getAsFunctionType()->getResultType()->isObjCInterfaceType()) {
+    Diag(D.getIdentifierLoc(),
+         diag::err_object_cannot_be_passed_returned_by_value) << 0
+      << R->getAsFunctionType()->getResultType();
+    InvalidDecl = true;
+  }
   
   bool isVirtualOkay = false;
   FunctionDecl *NewFD;
index fe14287c7edba4434469dd49e754dd97856f2668..73454022ba4df78bd09beba2e2bfd2eee591f49e 100644 (file)
@@ -31,6 +31,13 @@ void foo6(id (^objectCreationBlock)()) {
     return bar6(objectCreationBlock); // expected-warning{{incompatible block pointer types passing 'id (^)()', expected 'id (^)(int)'}}
 }
 
-void foo67(id (^x)(int)) {
+void foo7(id (^x)(int)) {
   if (x) { }
 }
+
+@interface itf
+@end
+
+void foo8() {
+  ^(itf x) {};
+}
index 1ef22a08516d8c67ea4e9015df689457d3a880e8..540000b248277fd0c838c2d490b922c74c6aaa3e 100644 (file)
@@ -27,7 +27,8 @@ struct whatever {
 }
 @end
 
-Super foo(Super parm1) { // expected-error{{Objective-C interface type 'Super' cannot be passed by value}}
+Super foo( // expected-error{{Objective-C interface type 'Super' cannot be returned by value}}
+          Super parm1) { // expected-error{{Objective-C interface type 'Super' cannot be passed by value}}
        Super p1; // expected-error{{Objective-C type cannot be statically allocated}}
        return p1;
 }
index 3667427d1a34f18f73884d40208d3acc20c66791..824f72d29be50c3a1ef4c544cde757340a53e73d 100644 (file)
@@ -21,3 +21,4 @@
 @end
 
 void somefunc(foo x) {} // expected-error {{Objective-C interface type 'foo' cannot be passed by value}}
+foo somefunc2() {} // expected-error {{Objective-C interface type 'foo' cannot be returned by value}}