objc: Issue diagnostic when receiver type is a forward class declaration and
it is treated as of 'id' type resulting in multiple method lookup.
// rdar://10686120


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@149653 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 1c48a83..b94b380 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -417,6 +417,8 @@
   "class implementation is declared here">;
 def note_class_declared : Note<
   "class is declared here">;
+def note_receiver_is_id : Note<
+  "receiver is treated with 'id' type for purpose of method lookup">;
 def note_suppressed_class_declare : Note<
   "class with specified objc_requires_property_definitions attribute is declared here">;
 def warn_dup_category_def : Warning<
@@ -3268,6 +3270,9 @@
   "no visible @interface for %0 declares the selector %1">;
 def err_arc_receiver_forward_instance : Error<
   "receiver type %0 for instance message is a forward declaration">;
+def warn_receiver_forward_instance : Warning<
+  "receiver type %0 for instance message is a forward declaration">,
+  InGroup<DiagGroup<"receiver-forward-class">>, DefaultIgnore;
 def err_arc_collection_forward : Error<
   "collection expression type %0 is a forward declaration">;
 def err_arc_multiple_method_decl : Error< 
diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp
index 82e8171..7e2180f 100644
--- a/lib/Sema/SemaExprObjC.cpp
+++ b/lib/Sema/SemaExprObjC.cpp
@@ -1380,11 +1380,15 @@
                 ? PDiag(diag::err_arc_receiver_forward_instance)
                     << (Receiver ? Receiver->getSourceRange() 
                                  : SourceRange(SuperLoc))
-                : PDiag())) {
+                : PDiag(diag::warn_receiver_forward_instance)
+                    << (Receiver ? Receiver->getSourceRange() 
+                                 : SourceRange(SuperLoc)))) {
           if (getLangOptions().ObjCAutoRefCount)
             return ExprError();
           
           forwardClass = OCIType->getInterfaceDecl();
+          Diag(Receiver ? Receiver->getLocStart() 
+                        : SuperLoc, diag::note_receiver_is_id);
           Method = 0;
         } else {
           Method = ClassDecl->lookupInstanceMethod(Sel);
diff --git a/test/SemaObjC/receiver-forward-class.m b/test/SemaObjC/receiver-forward-class.m
new file mode 100644
index 0000000..cefb5d7
--- /dev/null
+++ b/test/SemaObjC/receiver-forward-class.m
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -fsyntax-only -Wreceiver-forward-class -verify %s
+// RUN: %clang_cc1 -x objective-c++ -fsyntax-only  -Wreceiver-forward-class -verify %s
+// rdar://10686120
+
+@class A; // expected-note {{forward declaration of class here}}
+
+@interface B
+-(int) width; // expected-note {{using}}
+@end
+@interface C
+-(float) width; // expected-note {{also found}}
+@end
+
+int f0(A *x) {
+  return [x width]; // expected-warning {{receiver type 'A' for instance message is a forward declaration}} \
+                    // expected-warning {{multiple methods named 'width' found}} \
+                    // expected-note {{receiver is treated with 'id' type for purpose of method lookup}}
+}
+