Patch to fix a crash when using gnu's ?: with Objective-C++'s dictionary subscripting

jahanian fjahanian at apple.com
Fri May 17 09:38:54 PDT 2013


On May 16, 2013, at 9:43 PM, John McCall <rjmccall at apple.com> wrote:

> On May 16, 2013, at 5:11 PM, jahanian <fjahanian at apple.com> wrote:
>> 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
> 
> This is the right way to fix this, but (1) go ahead and filter out all the
> placeholder types instead of just pseudo-objects, and (2) please do
> that before this check so that we can do the right thing for getters
> of reference type.
> 
> That is, do this:
>  // Lower out placeholder types first.  This is important so that we don't
>  // try to capture a placeholder, and it also lets us do the right thing in
>  // a few cases in C++.
>  // the placeholder happens
>  if (commonExpr->hasPlaceholderType()) {
>    ExprResult result = CheckPlaceholderExpr(commonExpr);
>    if (!result.isUsable()) return ExprError();
>    commonExpr = result.take();
>  }
> 
> This should make us do the right thing with overloaded function
> references;  here's a test case for that:
> 
>  template <class T, class U = T> T foo(U x) { return x; }
>  ...
>  int (*fn)(int) = (&foo<int> ?: 0);
> 
> (this might not be *useful*, but it should *work*)
> 
> And here's an ObjC++ test case for a reference-valued property:
>  @interface A
>  - (int &) foo;
>  @end
>  ...
>  void test(A *a) {
>    int x = 0;
>    int &y = a.foo ?: x;
>  }

Somehow, these two tests were not adequate to show the necessity for more general lowering of placeholder types.
Regardless, r182120 does this as you suggested. Thanks for the detailed review.

- Fariborz

> 
> John.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130517/fb359bf6/attachment.html>


More information about the cfe-commits mailing list