]> granicus.if.org Git - clang/commitdiff
Change the type of ObjC @ string constants (from NSConstantString->NSString).
authorSteve Naroff <snaroff@apple.com>
Tue, 7 Apr 2009 14:18:33 +0000 (14:18 +0000)
committerSteve Naroff <snaroff@apple.com>
Tue, 7 Apr 2009 14:18:33 +0000 (14:18 +0000)
This fixes <rdar://problem/6757102> clang type for @"xxx" is "NSConstantString *" (GCC type is "NSString *").

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

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/objc-string-constant.m [new file with mode: 0644]

index bd94f007bad4d8706be69f8aa43c8dd0b235f64f..cfa279aa3111b5dd36e6daba661d1691707aa03e 100644 (file)
@@ -69,19 +69,21 @@ Sema::ExprResult Sema::ParseObjCStringLiteral(SourceLocation *AtLocs,
     return true;
 
   // Initialize the constant string interface lazily. This assumes
-  // the NSConstantString interface is seen in this translation unit.
+  // the NSString interface is seen in this translation unit. Note: We
+  // don't use NSConstantString, since the runtime team considers this
+  // interface private (even though it appears in the header files).
   QualType Ty = Context.getObjCConstantStringInterface();
   if (!Ty.isNull()) {
     Ty = Context.getPointerType(Ty);
   } else {
-    IdentifierInfo *NSIdent = &Context.Idents.get("NSConstantString");
+    IdentifierInfo *NSIdent = &Context.Idents.get("NSString");
     NamedDecl *IF = LookupName(TUScope, NSIdent, LookupOrdinaryName);
     if (ObjCInterfaceDecl *StrIF = dyn_cast_or_null<ObjCInterfaceDecl>(IF)) {
       Context.setObjCConstantStringInterface(StrIF);
       Ty = Context.getObjCConstantStringInterface();
       Ty = Context.getPointerType(Ty);
     } else {
-      // If there is no NSConstantString interface defined then treat constant
+      // If there is no NSString interface defined then treat constant
       // strings as untyped objects and let the runtime figure it out later.
       Ty = Context.getObjCIdType();
     }
diff --git a/test/SemaObjC/objc-string-constant.m b/test/SemaObjC/objc-string-constant.m
new file mode 100644 (file)
index 0000000..8baa149
--- /dev/null
@@ -0,0 +1,39 @@
+// RUN: clang-cc %s -verify -fsyntax-only &&
+
+#define nil 0       /* id of Nil instance */
+
+@interface NSObject 
+@end
+
+@interface NSString : NSObject
+
+@end
+
+@interface NSMutableString : NSString
+
+@end
+
+@interface NSSimpleCString : NSString {
+@protected
+    char *bytes;
+    int numBytes;
+}
+@end
+
+@interface NSConstantString : NSSimpleCString
+@end
+
+
+@interface Subclass : NSObject 
+- (NSString *)token;
+@end
+
+@implementation Subclass
+- (NSString *)token;
+{
+  NSMutableString *result = nil;
+
+  return (result != nil) ? result : @"";
+}
+@end
+