diff options
author | Chris Lattner <sabre@nondot.org> | 2009-04-11 19:17:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-04-11 19:17:25 +0000 |
commit | bb74982f30e295d91c2282a16862d674f88d636a (patch) | |
tree | 0bafb53c7b63eb82ce1e74394e6ef0ca8ff61475 | |
parent | 2dd979fbd59938babbed76e2376116511b403c93 (diff) |
diagnose attempts to return objc interfaces by-value from C functions.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68873 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 10 | ||||
-rw-r--r-- | test/SemaObjC/blocks.m | 9 | ||||
-rw-r--r-- | test/SemaObjC/invalid-objc-decls-1.m | 3 | ||||
-rw-r--r-- | test/SemaObjC/method-bad-param.m | 1 |
4 files changed, 20 insertions, 3 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index 5fe44d3089..d3f24cae90 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -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; diff --git a/test/SemaObjC/blocks.m b/test/SemaObjC/blocks.m index fe14287c7e..73454022ba 100644 --- a/test/SemaObjC/blocks.m +++ b/test/SemaObjC/blocks.m @@ -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) {}; +} diff --git a/test/SemaObjC/invalid-objc-decls-1.m b/test/SemaObjC/invalid-objc-decls-1.m index 1ef22a0851..540000b248 100644 --- a/test/SemaObjC/invalid-objc-decls-1.m +++ b/test/SemaObjC/invalid-objc-decls-1.m @@ -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; } diff --git a/test/SemaObjC/method-bad-param.m b/test/SemaObjC/method-bad-param.m index 3667427d1a..824f72d29b 100644 --- a/test/SemaObjC/method-bad-param.m +++ b/test/SemaObjC/method-bad-param.m @@ -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}} |