]> granicus.if.org Git - clang/commitdiff
In debugger support mode, if we have a top-level message send
authorDouglas Gregor <dgregor@apple.com>
Thu, 15 Dec 2011 00:53:32 +0000 (00:53 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 15 Dec 2011 00:53:32 +0000 (00:53 +0000)
expression with an unknown result type, assume that the result type is
'id'. Fixes <rdar://problem/10400663>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146622 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprCXX.cpp
test/SemaObjC/unknown-anytype.m
test/SemaObjCXX/unknown-anytype.mm

index 59369d603d9936edbf849bc2f39b8ca75635312e..e7e6b892e524faaaea340f3285c07b3f9fd0912e 100644 (file)
@@ -4674,6 +4674,15 @@ ExprResult Sema::ActOnFinishFullExpr(Expr *FE) {
   if (DiagnoseUnexpandedParameterPack(FullExpr.get()))
     return ExprError();
 
+  // Top-level message sends default to 'id' when we're in a debugger.
+  if (getLangOptions().DebuggerSupport &&
+      FullExpr.get()->getType() == Context.UnknownAnyTy &&
+      isa<ObjCMessageExpr>(FullExpr.get())) {
+    FullExpr = forceUnknownAnyToType(FullExpr.take(), Context.getObjCIdType());
+    if (FullExpr.isInvalid())
+      return ExprError();
+  }
+  
   FullExpr = CheckPlaceholderExpr(FullExpr.take());
   if (FullExpr.isInvalid())
     return ExprError();
index 48eb91ae2372010bd45d021fabb1b4c0e7ab889c..89e45e4a1317f86b9e7995166c1fe040456a6945 100644 (file)
@@ -17,8 +17,13 @@ void test_unknown_anytype_receiver() {
   int *ip = [test0 getIntPtr];
   float *fp = [test1() getFloatPtr];
   double *dp = [test1() getSomePtr]; // okay: picks first method found
-  [[test0 unknownMethod] otherUnknownMethod]; // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}}
+  [[test0 unknownMethod] otherUnknownMethod]; 
   (void)(int)[[test0 unknownMethod] otherUnknownMethod];;
-  [[test1() unknownMethod] otherUnknownMethod]; // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}}
+  [[test1() unknownMethod] otherUnknownMethod];
   (void)(id)[[test1() unknownMethod] otherUnknownMethod];
+
+  if ([[test0 unknownMethod] otherUnknownMethod]) { // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}}
+  }
+  if ([[test1() unknownMethod] otherUnknownMethod]) { // expected-error{{no known method '-otherUnknownMethod'; cast the message send to the method's return type}}
+  }
 }
index 163dddee708ffda6972d49a3c3c875942bc97626..40954c85ebe012afdd27da20200d356dc08e9045 100644 (file)
@@ -3,6 +3,7 @@
 // rdar://problem/9416370
 namespace test0 {
   void test(id x) {
-    [x foo]; // expected-error {{no known method '-foo'; cast the message send to the method's return type}}
+    if ([x foo]) {} // expected-error {{no known method '-foo'; cast the message send to the method's return type}}
+    [x foo];
   }
 }