More type checking for properties, accessors and
use of dot-syntax expression. This is to match gcc's.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@71243 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp
index e35b7a9..34afded 100644
--- a/lib/Sema/SemaDeclObjC.cpp
+++ b/lib/Sema/SemaDeclObjC.cpp
@@ -1315,11 +1315,17 @@
if (GetterMethod &&
GetterMethod->getResultType() != property->getType()) {
- Diag(property->getLocation(),
- diag::err_accessor_property_type_mismatch)
- << property->getDeclName()
- << GetterMethod->getSelector();
- Diag(GetterMethod->getLocation(), diag::note_declared_at);
+ AssignConvertType result = Incompatible;
+ if (Context.isObjCObjectPointerType(property->getType()))
+ result = CheckAssignmentConstraints(property->getType(),
+ GetterMethod->getResultType());
+ if (result != Compatible) {
+ Diag(property->getLocation(),
+ diag::warn_accessor_property_type_mismatch)
+ << property->getDeclName()
+ << GetterMethod->getSelector();
+ Diag(GetterMethod->getLocation(), diag::note_declared_at);
+ }
}
if (SetterMethod) {
@@ -1329,7 +1335,7 @@
if (SetterMethod->param_size() != 1 ||
((*SetterMethod->param_begin())->getType() != property->getType())) {
Diag(property->getLocation(),
- diag::err_accessor_property_type_mismatch)
+ diag::warn_accessor_property_type_mismatch)
<< property->getDeclName()
<< SetterMethod->getSelector();
Diag(SetterMethod->getLocation(), diag::note_declared_at);
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 79c471a..f698620 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2096,8 +2096,21 @@
// Check whether we can reference this property.
if (DiagnoseUseOfDecl(PD, MemberLoc))
return ExprError();
-
- return Owned(new (Context) ObjCPropertyRefExpr(PD, PD->getType(),
+ QualType ResTy = PD->getType();
+ Selector Sel = PP.getSelectorTable().getNullarySelector(&Member);
+ ObjCMethodDecl *Getter = IFace->lookupInstanceMethod(Context, Sel);
+ if (Getter) {
+ AssignConvertType result =
+ CheckAssignmentConstraints(PD->getType(), Getter->getResultType());
+ if (result != Compatible) {
+ Diag(MemberLoc, diag::warn_accessor_property_type_mismatch)
+ << PD->getDeclName() << Sel;
+ Diag(Getter->getLocation(), diag::note_declared_at);
+ ResTy = Getter->getResultType();
+ }
+ }
+
+ return Owned(new (Context) ObjCPropertyRefExpr(PD, ResTy,
MemberLoc, BaseExpr));
}