]> granicus.if.org Git - clang/commitdiff
Objective-C arc [qui]. Don't issue the bridge cast
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 2 Apr 2013 23:48:59 +0000 (23:48 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Tue, 2 Apr 2013 23:48:59 +0000 (23:48 +0000)
warning when doing a __bride cast in non-arc
mode (which has no retain count effect).
// rdar://13514210

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

lib/Parse/ParseExpr.cpp
test/FixIt/bridge-in-non-arc.m
test/SemaObjC/illegal-nonarc-bridged-cast.m

index 4bb2bf2eba67a370f573f58d5ce143925a7bc88d..956ba36d3c8812ab47c63be04a54c8ba8600d8e1 100644 (file)
@@ -1961,12 +1961,16 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr,
                       Tok.is(tok::kw___bridge_retained) ||
                       Tok.is(tok::kw___bridge_retain)));
   if (BridgeCast && !getLangOpts().ObjCAutoRefCount) {
-    StringRef BridgeCastName = Tok.getName();
-    SourceLocation BridgeKeywordLoc = ConsumeToken();
-    if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
-      Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
-        << BridgeCastName
-        << FixItHint::CreateReplacement(BridgeKeywordLoc, "");
+    if (Tok.isNot(tok::kw___bridge)) {
+      StringRef BridgeCastName = Tok.getName();
+      SourceLocation BridgeKeywordLoc = ConsumeToken();
+      if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc))
+        Diag(BridgeKeywordLoc, diag::warn_arc_bridge_cast_nonarc)
+          << BridgeCastName
+          << FixItHint::CreateReplacement(BridgeKeywordLoc, "");
+    }
+    else
+      ConsumeToken(); // consume __bridge
     BridgeCast = false;
   }
   
index 948fa8ebcc130605f5abcf0ec8fab5797f28fccf..b4d2677be073bf96973160b26830974d952e76ee 100644 (file)
@@ -4,9 +4,9 @@
 @end
 
 void foo(void *p) {
-  I *i = (__bridge I*)p;
-  I *i2 = (__bridge/*cake*/I*)p;
+  I *i = (__bridge_transfer I*)p;
+  I *i2 = (__bridge_transfer/*cake*/I*)p;
 }
 
-// CHECK: {7:11-7:20}:""
-// CHECK: {8:12-8:20}:""
+// CHECK: {7:11-7:29}:""
+// CHECK: {8:12-8:29}:""
index a5bb01ffe0a8a962118cdb034dddd7e475ca6fbd..f3406ef983cc505b87a710945e3f97839f87eaf4 100644 (file)
@@ -18,17 +18,16 @@ NSString *CreateNSString();
 void from_cf() {
   id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
   id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-warning {{'__bridge_transfer' casts have no effect when not using ARC}}
-  (__bridge int*)CFCreateSomething();  // expected-warning {{'__bridge' casts have no effect when not using ARC}}  \
-                                       // expected-warning {{expression result unused}}
-  id obj3 = (__bridge id)CFGetSomething(); // expected-warning {{'__bridge' casts have no effect when not using ARC}}
-  id obj4 = (__bridge NSString*)CFGetString(); // expected-warning {{'__bridge' casts have no effect when not using ARC}}
+  (__bridge int*)CFCreateSomething(); // expected-warning {{expression result unused}}
+  id obj3 = (__bridge id)CFGetSomething();
+  id obj4 = (__bridge NSString*)CFGetString();
 }
 
 void to_cf(id obj) {
   CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
   CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning {{'__bridge_retained' casts have no effect when not using ARC}}
-  CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // expected-warning {{'__bridge' casts have no effect when not using ARC}}
-  CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); // expected-warning {{'__bridge' casts have no effect when not using ARC}} 
+  CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething();
+  CFStringRef cf4 = (__bridge CFStringRef)CreateNSString();
 }
 
 void fixits() {