[PATCH] D32759: Fix errored return value in CheckFunctionReturnType and add a fixit hint

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 13:16:38 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL302720: Fix errored return value in CheckFunctionReturnType and add a fixit hint (authored by erichkeane).

Changed prior to commit:
  https://reviews.llvm.org/D32759?vs=98504&id=98516#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32759

Files:
  cfe/trunk/lib/Sema/SemaType.cpp
  cfe/trunk/test/SemaObjC/method-bad-param.m
  cfe/trunk/test/SemaObjCXX/interface-return-type.mm


Index: cfe/trunk/test/SemaObjC/method-bad-param.m
===================================================================
--- cfe/trunk/test/SemaObjC/method-bad-param.m
+++ cfe/trunk/test/SemaObjC/method-bad-param.m
@@ -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'}}
 
Index: cfe/trunk/test/SemaObjCXX/interface-return-type.mm
===================================================================
--- cfe/trunk/test/SemaObjCXX/interface-return-type.mm
+++ cfe/trunk/test/SemaObjCXX/interface-return-type.mm
@@ -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}}
Index: cfe/trunk/lib/Sema/SemaType.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp
+++ cfe/trunk/lib/Sema/SemaType.cpp
@@ -2285,8 +2285,9 @@
   // 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32759.98516.patch
Type: text/x-patch
Size: 2027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170510/3eab438c/attachment-0001.bin>


More information about the cfe-commits mailing list