]> granicus.if.org Git - clang/commitdiff
lldb support: under debugger support flag, when sending message
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Mar 2012 18:47:16 +0000 (18:47 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 9 Mar 2012 18:47:16 +0000 (18:47 +0000)
to forward class, and assigning to an 'id' type var, message
sends default to 'id'. // rdar"//10988847

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

lib/Sema/SemaDecl.cpp
test/SemaObjC/debugger-cast-result-to-id.m
test/SemaObjCXX/debugger-cast-result-to-id.mm

index 7957473a6babdf079f1ae567dfdaf0dac825c9b5..6c25a20e248634fb51414015e4eb45dc12488e37 100644 (file)
@@ -6209,6 +6209,18 @@ void Sema::AddInitializerToDecl(Decl *RealDecl, Expr *Init,
   // Get the decls type and save a reference for later, since
   // CheckInitializerTypes may change it.
   QualType DclT = VDecl->getType(), SavT = DclT;
+  
+  // Top-level message sends default to 'id' when we're in a debugger
+  // and we are assigning it to a variable of 'id' type.
+  if (getLangOptions().DebuggerCastResultToId && DclT->isObjCIdType())
+    if (Init->getType() == Context.UnknownAnyTy && isa<ObjCMessageExpr>(Init)) {
+      ExprResult Result = forceUnknownAnyToType(Init, Context.getObjCIdType());
+      if (Result.isInvalid()) {
+        VDecl->setInvalidDecl();
+        return;
+      }
+      Init = Result.take();
+    }
 
   // Perform the initialization.
   if (!VDecl->isInvalidDecl()) {
index 81a630703e7c39578cbdf3f16d0ca0a205f7b1d6..00a02be2c3081842b74c84b612058c323ea7d066 100644 (file)
@@ -7,3 +7,10 @@ void test_unknown_anytype_receiver() {
   (void)(int)[[test0 unknownMethod] otherUnknownMethod];;
   (void)(id)[[test1() unknownMethod] otherUnknownMethod];
 }
+
+// rdar://10988847
+@class NSString; // expected-note {{forward declaration of class here}}
+
+void rdar10988847() {
+  id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}}
+}
index 9487a22b6c4f54ae71d26c25afb92133d3f5f688..cd7aa7b6ac0bc158eb101270e0298583c19ec226 100644 (file)
@@ -7,3 +7,11 @@ namespace test0 {
     [x foo];
   }
 }
+
+// rdar://10988847
+@class NSString; // expected-note {{forward declaration of class here}}
+namespace test1 {
+  void rdar10988847() {
+    id s = [NSString stringWithUTF8String:"foo"]; // expected-warning {{receiver 'NSString' is a forward class and corresponding @interface may not exist}}
+  }
+}