]> granicus.if.org Git - clang/commitdiff
ObjectiveC ARC. Only briding of pointer to struct CF object is allowed.
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 15 Nov 2013 23:14:45 +0000 (23:14 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 15 Nov 2013 23:14:45 +0000 (23:14 +0000)
Improve on wording on illegal objc_bridge argumment.
// rdar://15454846

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

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclAttr.cpp
lib/Sema/SemaExprObjC.cpp
test/SemaObjC/objcbridge-attribute.m

index c34dd21af95f0c69488487c4f231830dba44ff13..a0cf4b6f6d1ece7194d435713c4c00f76068b9f7 100644 (file)
@@ -2445,11 +2445,10 @@ def err_objc_bridge_attribute : Error<
   "'objc_bridge' attribute must be put on a typedef only">;
 def err_objc_bridge_not_cftype : Error<
   "'objc_bridge' attribute must be applied to definition of CF types">;
-def err_objc_bridge_not_pointertype : Error<
-  "'objc_bridge' attribute must be applied to a pointer type">;
+def err_objc_bridge_not_pointert_to_struct : Error<
+  "'objc_bridge' attribute must be applied to a pointer to struct type">;
 def err_objc_bridged_not_interface : Error<
-  "CF object of type %0 with 'objc_bridge' attribute which has parameter that"
-  " does not name an Objective-C class">;
+  "CF object of type %0 is bridged to '%1', which is not an Objective-C class">;
 
 // Function Parameter Semantic Analysis.
 def err_param_with_void_type : Error<"argument may not have 'void' type">;
index 30ddd4d51d6366cf657e883969c1e1aa930b92ad..7987a18f6105ab1a0377ac57a87bcf09675eb908 100644 (file)
@@ -4403,13 +4403,18 @@ static void handleObjCBridgeAttr(Sema &S, Scope *Sc, Decl *D,
       if (T->isRecordType()) {
         RecordDecl *RD = T->getAs<RecordType>()->getDecl();
         if (!RD || RD->isUnion()) {
-          S.Diag(D->getLocStart(), diag::err_attribute_wrong_decl_type)
-          << Attr.getRange() << Attr.getName() << ExpectedStruct;
+          S.Diag(D->getLocStart(), diag::err_objc_bridge_not_pointert_to_struct)
+          << Attr.getRange();
           return;
         }
+      } else {
+        S.Diag(TD->getLocStart(), diag::err_objc_bridge_not_pointert_to_struct)
+        << Attr.getRange();
+        return;
       }
     } else {
-      S.Diag(TD->getLocStart(), diag::err_objc_bridge_not_pointertype);
+      S.Diag(TD->getLocStart(), diag::err_objc_bridge_not_pointert_to_struct)
+            << Attr.getRange();
       return;
     }
     // Check for T being a CFType goes here.
index 6ff6bef1ec7527f550b48d1d399b04b09495e7cb..e72519c3edf738354a8035343f3e079c90283a1b 100644 (file)
@@ -3180,13 +3180,13 @@ static bool CheckObjCBridgeCast(Sema &S, QualType castType, Expr *castExpr) {
           NamedDecl *Target = R.getFoundDecl();
           if (Target && !isa<ObjCInterfaceDecl>(Target)) {
             S.Diag(castExpr->getLocStart(), diag::err_objc_bridged_not_interface)
-                    << castExpr->getType();
+                    << castExpr->getType() << Parm->getName();
             S.Diag(TDNDecl->getLocStart(), diag::note_declared_at);
             S.Diag(Target->getLocStart(), diag::note_declared_at);
           }
         } else {
           S.Diag(castExpr->getLocStart(), diag::err_objc_bridged_not_interface)
-                  << castExpr->getType();
+                  << castExpr->getType() << Parm->getName();
           S.Diag(TDNDecl->getLocStart(), diag::note_declared_at);
         }
       }
index bb2d3e28515f324a8924b93592f5b9b4fc7d0c40..3178f17a7cd6b4c898d23f561fbe2f688b43e207 100644 (file)
@@ -7,19 +7,19 @@ typedef struct __CFMyColor  * __attribute__((objc_bridge(12))) CFMyColorRef; //
 
 typedef struct __CFArray *  __attribute__ ((objc_bridge)) CFArrayRef; // expected-error {{parameter of 'objc_bridge' attribute must be a single name of an Objective-C class}}
 
-typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef; 
+typedef void *  __attribute__ ((objc_bridge(NSURL))) CFURLRef;  // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
 
-typedef void * CFStringRef __attribute__ ((objc_bridge(NSString)));
+typedef void * CFStringRef __attribute__ ((objc_bridge(NSString))); // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
 
 typedef struct __CFLocale * __attribute__((objc_bridge(NSLocale, NSError))) CFLocaleRef;// expected-error {{use of undeclared identifier 'NSError'}}
 
-typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer type}}
+typedef struct __CFData __attribute__((objc_bridge(NSData))) CFDataRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
 
 typedef struct __attribute__((objc_bridge(NSDictionary))) __CFDictionary * CFDictionaryRef; // expected-error {{'objc_bridge' attribute must be put on a typedef only}}
 
 typedef struct __CFSetRef * CFSetRef __attribute__((objc_bridge(NSSet)));
 
-typedef union __CFUColor * __attribute__((objc_bridge(NSUColor))) CFUColorRef; // expected-error {{'objc_bridge' attribute only applies to structs}}
+typedef union __CFUColor * __attribute__((objc_bridge(NSUColor))) CFUColorRef; // expected-error {{'objc_bridge' attribute must be applied to a pointer to struct type}}
 
 @interface I
 {
@@ -34,7 +34,7 @@ typedef union __CFUColor * __attribute__((objc_bridge(NSUColor))) CFUColorRef; /
 typedef struct __CFError * __attribute__((objc_bridge(NSTesting))) CFTestingRef; // expected-note {{declared here}}
 
 id Test1(CFTestingRef cf) {
-  return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') with 'objc_bridge' attribute which has parameter that does not name an Objective-C class}}
+  return (NSString *)cf; // expected-error {{CF object of type 'CFTestingRef' (aka 'struct __CFError *') is bridged to 'NSTesting', which is not an Objective-C class}}
 }
 
 typedef CFErrorRef CFErrorRef1;