Attached patch fixes a sema crash when gnu’s ?: extension is used for Objective-C++’s dictionary subscripting. This is done by essentially allowing application of unary conversion on the common _expression_ when its type is pseudo-object type. (common _expression_ is ObjCSubscriptRefExpr with the pseudo-object type which is not suitable for the lhs _expression_ of the conditional). Please review. This is for // rdar://13749180 - Fariborz |
Index: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp (revision 182014)
+++ lib/Sema/SemaExpr.cpp (working copy)
@@ -5639,7 +5639,8 @@
&& commonExpr->isGLValue()
&& commonExpr->isOrdinaryOrBitFieldObject()
&& RHSExpr->isOrdinaryOrBitFieldObject()
- && Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) {
+ && Context.hasSameType(commonExpr->getType(), RHSExpr->getType())
+ && !Context.hasSameType(commonExpr->getType(),
Context.PseudoObjectTy))) {
ExprResult commonRes = UsualUnaryConversions(commonExpr);
if (commonRes.isInvalid())
return ExprError();
Index: test/SemaObjCXX/literals.mm
===================================================================
--- test/SemaObjCXX/literals.mm (revision 182014)
+++ test/SemaObjCXX/literals.mm (working copy)
@@ -185,3 +185,15 @@
void test_dictionary_colon() {
id dict = @{ key : value };
}
+
+// rdar://13749180
+@interface NSDictionary()
+- (id)objectForKeyedSubscript:(id)key;
+- (void)setObject:(id)object forKeyedSubscript:(id)key;
+@end
+
+@class NSString;
+void rdar13749180() {
+ NSDictionary* foo;
+ NSString* result = foo[@"bar"] ? : foo[@"baz"];
+}
_______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
