r302720 - Fix errored return value in CheckFunctionReturnType and add a fixit hint
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed May 10 13:03:17 PDT 2017
Author: erichkeane
Date: Wed May 10 15:03:16 2017
New Revision: 302720
URL: http://llvm.org/viewvc/llvm-project?rev=302720&view=rev
Log:
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
Added:
cfe/trunk/test/SemaObjCXX/interface-return-type.mm
Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaObjC/method-bad-param.m
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=302720&r1=302719&r2=302720&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed May 10 15:03:16 2017
@@ -2285,8 +2285,9 @@ bool Sema::CheckFunctionReturnType(QualT
// Methods cannot return interface types. All ObjC objects are
// passed by reference.
if (T->isObjCObjectType()) {
- Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value) << 0 << T;
- return 0;
+ Diag(Loc, diag::err_object_cannot_be_passed_returned_by_value)
+ << 0 << T << FixItHint::CreateInsertion(Loc, "*");
+ return true;
}
return false;
Modified: cfe/trunk/test/SemaObjC/method-bad-param.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-bad-param.m?rev=302720&r1=302719&r2=302720&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-bad-param.m (original)
+++ cfe/trunk/test/SemaObjC/method-bad-param.m Wed May 10 15:03:16 2017
@@ -20,6 +20,12 @@
}
@end
+// Ensure that this function is properly marked as a failure.
+void func_with_bad_call(bar* b, foo* f) {
+ [b cccccc:5]; // expected-warning {{instance method '-cccccc:' not found}}
+ // expected-note at -17 {{receiver is instance of class declared here}}
+}
+
void somefunc(foo x) {} // expected-error {{interface type 'foo' cannot be passed by value; did you forget * in 'foo'}}
foo somefunc2() {} // expected-error {{interface type 'foo' cannot be returned by value; did you forget * in 'foo'}}
Added: cfe/trunk/test/SemaObjCXX/interface-return-type.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/interface-return-type.mm?rev=302720&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjCXX/interface-return-type.mm (added)
+++ cfe/trunk/test/SemaObjCXX/interface-return-type.mm Wed May 10 15:03:16 2017
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 %s -verify
+
+ at class NSObject;
+template<typename T> struct C {
+ static T f(); // expected-error {{interface type 'NSObject' cannot be returned by value; did you forget * in 'NSObject'?}}
+};
+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}}
More information about the cfe-commits
mailing list