Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 84e1942

Browse files
author
Erich Keane
committed
Fix errored return value in CheckFunctionReturnType and add a fixit hint
As discovered by ChenWJ and listed on cfe-dev, the error for Objective C return type ended up being wrong. This fixes that. Additionally, as a "while we're there", the other usages of this error and the usage of the FP above both use a FixItHint, so I'll add it here. Differential Revision: https://reviews.llvm.org/D32759 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302720 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 0302d8d commit 84e1942

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Diff for: lib/Sema/SemaType.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -2285,8 +2285,9 @@ bool Sema::CheckFunctionReturnType(QualType T, SourceLocation Loc) {
22852285
// Methods cannot return interface types. All ObjC objects are
22862286
// passed by reference.
22872287
if (T->isObjCObjectType()) {
2288-
Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value) << 0 << T;
2289-
return 0;
2288+
Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value)
2289+
<< 0 << T << FixItHint::CreateInsertion(Loc, "*");
2290+
return true;
22902291
}
22912292

22922293
return false;

Diff for: test/SemaObjC/method-bad-param.m

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ - (foo)cccccc:(long)ddddd // expected-error {{interface type 'foo' cannot be ret
2020
}
2121
@end
2222

23+
// Ensure that this function is properly marked as a failure.
24+
void func_with_bad_call(bar* b, foo* f) {
25+
[b cccccc:5]; // expected-warning {{instance method '-cccccc:' not found}}
26+
// expected-note@-17 {{receiver is instance of class declared here}}
27+
}
28+
2329
void somefunc(foo x) {} // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}}
2430
foo somefunc2() {} // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}}
2531

Diff for: test/SemaObjCXX/interface-return-type.mm

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
2+
3+
@class NSObject;
4+
template<typename T> struct C {
5+
static T f(); // expected-error {{interface type 'NSObject' cannot be returned by value; did you forget * in 'NSObject'?}}
6+
};
7+
int g() { NSObject *x = C<NSObject>::f(); }//expected-error {{no member named 'f' in 'C<NSObject>'}} expected-note {{in instantiation of template class 'C<NSObject>' requested here}}

0 commit comments

Comments
 (0)