[cfe-commits] r134706 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaCXXCast.cpp lib/Sema/SemaExpr.cpp lib/Sema/SemaExprCXX.cpp test/SemaObjC/arc-unavailable-for-weakref.m test/SemaObjCXX/arc-unavailable-for-weakref.mm
Fariborz Jahanian
fjahanian at apple.com
Fri Jul 8 10:41:42 PDT 2011
Author: fjahanian
Date: Fri Jul 8 12:41:42 2011
New Revision: 134706
URL: http://llvm.org/viewvc/llvm-project?rev=134706&view=rev
Log:
objc++-arc: more diagnosis of converting a weak-unavailable
object to a __weak object type. // rdar://9732636
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaCXXCast.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jul 8 12:41:42 2011
@@ -2574,9 +2574,9 @@
"class is incompatible with __weak references">;
def err_arc_weak_unavailable_assign : Error<
"assignment of a weak-unavailable object to a __weak object">;
-def err_arc_cast_of_weak_unavailable : Error<
- "cast of weak-unavailable object of type %0 to"
- " a __weak object of type %1">;
+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">;
def err_arc_illegal_explicit_message : Error<
"ARC forbids explicit message send of %0">;
def err_arc_unused_init_message : Error<
Modified: cfe/trunk/lib/Sema/SemaCXXCast.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCXXCast.cpp?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaCXXCast.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCXXCast.cpp Fri Jul 8 12:41:42 2011
@@ -1774,15 +1774,8 @@
}
}
- if (getLangOptions().ObjCAutoRefCount && tcr == TC_Success) {
+ if (getLangOptions().ObjCAutoRefCount && tcr == TC_Success)
CheckObjCARCConversion(R, CastTy, CastExpr, CCK);
- if (!CheckObjCARCUnavailableWeakConversion(CastTy,
- origCastExprType))
- Diag(CastExpr->getLocStart(),
- diag::err_arc_cast_of_weak_unavailable)
- << origCastExprType << CastTy
- << CastExpr->getSourceRange();
- }
if (tcr != TC_Success && msg != 0) {
if (CastExpr->getType() == Context.OverloadTy) {
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Jul 8 12:41:42 2011
@@ -4068,7 +4068,7 @@
}
else if (!CheckObjCARCUnavailableWeakConversion(castType, castExprType)) {
Diag(castExpr->getLocStart(),
- diag::err_arc_cast_of_weak_unavailable)
+ diag::err_arc_convesion_of_weak_unavailable) << 1
<< castExprType << castType
<< castExpr->getSourceRange();
return ExprError();
Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Fri Jul 8 12:41:42 2011
@@ -2340,8 +2340,20 @@
if (From->getType()->isObjCObjectPointerType() &&
ToType->isObjCObjectPointerType())
EmitRelatedResultTypeNote(From);
- }
-
+ }
+ else if (getLangOptions().ObjCAutoRefCount &&
+ !CheckObjCARCUnavailableWeakConversion(ToType,
+ From->getType())) {
+ if (Action == AA_Initializing)
+ Diag(From->getSourceRange().getBegin(),
+ diag::err_arc_weak_unavailable_assign);
+ else
+ Diag(From->getSourceRange().getBegin(),
+ diag::err_arc_convesion_of_weak_unavailable)
+ << (Action == AA_Casting) << From->getType() << ToType
+ << From->getSourceRange();
+ }
+
CastKind Kind = CK_Invalid;
CXXCastPath BasePath;
if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle))
Modified: cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m (original)
+++ cfe/trunk/test/SemaObjC/arc-unavailable-for-weakref.m Fri Jul 8 12:41:42 2011
@@ -24,7 +24,7 @@
+ (id) new;
@end
-NOWEAK * Test9732636() {
+NOWEAK * Test1() {
NOWEAK * strong1 = [NOWEAK new];
__weak id weak1;
weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
@@ -33,3 +33,15 @@
return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}}
}
+ at protocol P @end
+ at protocol P1 @end
+
+NOWEAK<P, P1> * Test2() {
+ NOWEAK<P, P1> * strong1 = 0;
+ __weak id<P> weak1;
+ weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+
+ __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+ return (__weak id<P>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P>'}}
+}
+
Modified: cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm?rev=134706&r1=134705&r2=134706&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm (original)
+++ cfe/trunk/test/SemaObjCXX/arc-unavailable-for-weakref.mm Fri Jul 8 12:41:42 2011
@@ -24,13 +24,24 @@
+ (id) new;
@end
-NOWEAK * Test9732636() {
+NOWEAK * Test1() {
NOWEAK * strong1 = [NOWEAK new];
__weak id weak1;
weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
-// FIXME. NYI.
- __weak id weak2 = strong1; // expected-FIXME {{assignment of a weak-unavailable object to a __weak object}}
- return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *__strong' to a __weak object of type '__weak id'}}
+ __weak id weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+ return (__weak id)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK *' to a __weak object of type '__weak id'}}
+}
+
+ at protocol P @end
+ at protocol P1 @end
+
+NOWEAK<P, P1> * Test2() {
+ NOWEAK<P, P1> * strong1 = 0;
+ __weak id<P> weak1;
+ weak1 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+
+ __weak id<P> weak2 = strong1; // expected-error {{assignment of a weak-unavailable object to a __weak object}}
+ return (__weak id<P, P1>)strong1; // expected-error {{cast of weak-unavailable object of type 'NOWEAK<P,P1> *' to a __weak object of type '__weak id<P,P1>'}}
}
More information about the cfe-commits
mailing list