Objective-C arc: Improve disgnostics when 'weak'
property cannot be synthesized because its backing
ivar does not support weak references.
// rdar://13676793
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180211 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 6ba65c0..0e5baf9 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3789,8 +3789,10 @@
def err_arc_weak_unavailable_assign : Error<
"assignment of a weak-unavailable object to a __weak object">;
def err_arc_weak_unavailable_property : Error<
- "synthesis of a weak-unavailable property is disallowed "
- "because it requires synthesis of an instance variable of the __weak object">;
+ "synthesizing __weak instance variable of type %0, which does not "
+ "support weak references">;
+def note_implemented_by_class : Note<
+ "when implemented by class %0">;
def err_arc_convesion_of_weak_unavailable : Error<
"%select{implicit conversion|cast}0 of weak-unavailable object of type %1 to"
" a __weak object of type %2">;
diff --git a/lib/Sema/SemaObjCProperty.cpp b/lib/Sema/SemaObjCProperty.cpp
index 2efd43e..2162bf0 100644
--- a/lib/Sema/SemaObjCProperty.cpp
+++ b/lib/Sema/SemaObjCProperty.cpp
@@ -996,8 +996,10 @@
PropertyIvarType->getAs<ObjCObjectPointerType>()) {
const ObjCInterfaceDecl *ObjI = ObjT->getInterfaceDecl();
if (ObjI && ObjI->isArcWeakrefUnavailable()) {
- Diag(PropertyDiagLoc, diag::err_arc_weak_unavailable_property);
- Diag(property->getLocation(), diag::note_property_declare);
+ Diag(property->getLocation(),
+ diag::err_arc_weak_unavailable_property) << PropertyIvarType;
+ Diag(ClassImpDecl->getLocation(), diag::note_implemented_by_class)
+ << ClassImpDecl->getName();
err = true;
}
}
diff --git a/test/SemaObjC/arc-unavailable-for-weakref.m b/test/SemaObjC/arc-unavailable-for-weakref.m
index b140c64..b9b5cc5 100644
--- a/test/SemaObjC/arc-unavailable-for-weakref.m
+++ b/test/SemaObjC/arc-unavailable-for-weakref.m
@@ -56,9 +56,33 @@
@interface I
{
}
-@property (weak) NSFont *font; // expected-note {{property declared here}}
+@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}}
@end
-@implementation I
-@synthesize font = _font; // expected-error {{synthesis of a weak-unavailable property is disallowed because it requires synthesis of an instance variable of the __weak object}}
+@implementation I // expected-note {{when implemented by class I}}
+@synthesize font = _font;
+@end
+
+// rdar://13676793
+@protocol MyProtocol
+@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}}
+@end
+
+@interface I1 <MyProtocol>
+@end
+
+@implementation I1 // expected-note {{when implemented by class I1}}
+@synthesize font = _font;
+@end
+
+@interface Super
+@property (weak) NSFont *font; // expected-error {{synthesizing __weak instance variable of type 'NSFont *', which does not support weak references}}
+@end
+
+
+@interface I2 : Super
+@end
+
+@implementation I2 // expected-note {{when implemented by class I2}}
+@synthesize font = _font;
@end