From e2eb0e997320c629b2762b56b911bff43187acaa Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 19 Dec 2011 22:52:53 +0000 Subject: [PATCH] objc-arc: bridge casts in non-arc mode are now error. // rdar://10597832 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146918 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticParseKinds.td | 5 ++--- lib/Parse/ParseExpr.cpp | 2 +- test/PCH/Inputs/arc.h | 10 ++++++++-- test/SemaObjC/illegal-nonarc-bridged-cast.m | 18 +++++++++--------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/clang/Basic/DiagnosticParseKinds.td b/include/clang/Basic/DiagnosticParseKinds.td index 7ce2a8e928..7a3e0e6a71 100644 --- a/include/clang/Basic/DiagnosticParseKinds.td +++ b/include/clang/Basic/DiagnosticParseKinds.td @@ -326,9 +326,8 @@ def err_illegal_super_cast : Error< let CategoryName = "ARC Parse Issue" in { def err_arc_bridge_retain : Error< "unknown cast annotation __bridge_retain; did you mean __bridge_retained?">; -def warn_arc_bridge_retain : Warning< - "bridge casts will have no effect in non-arc mode and will be ignored">, - InGroup>; +def err_arc_bridge_cast : Error< + "bridge casts will have no effect in non-arc mode">; } def err_objc_illegal_visibility_spec : Error< diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp index bb446f5ab2..bb26e28c12 100644 --- a/lib/Parse/ParseExpr.cpp +++ b/lib/Parse/ParseExpr.cpp @@ -1826,7 +1826,7 @@ Parser::ParseParenExpression(ParenParseOption &ExprType, bool stopIfCastExpr, if (BridgeCast && !getLang().ObjCAutoRefCount) { SourceLocation BridgeKeywordLoc = ConsumeToken(); if (!PP.getSourceManager().isInSystemHeader(BridgeKeywordLoc)) - Diag(BridgeKeywordLoc, diag::warn_arc_bridge_retain) + Diag(BridgeKeywordLoc, diag::err_arc_bridge_cast) << FixItHint::CreateReplacement(BridgeKeywordLoc, ""); BridgeCast = false; diff --git a/test/PCH/Inputs/arc.h b/test/PCH/Inputs/arc.h index 793fc643f2..304e612a0d 100644 --- a/test/PCH/Inputs/arc.h +++ b/test/PCH/Inputs/arc.h @@ -14,7 +14,13 @@ CFStringRef CFGetString(); id CreateSomething(); NSString *CreateNSString(); -typedef int array0[sizeof((__bridge id)CFCreateSomething())]; -typedef int array1[sizeof((__bridge CFTypeRef)CreateSomething())]; +#if __has_feature(objc_arc) +#define BRIDGE __bridge +#else +#define BRIDGE +#endif + +typedef int array0[sizeof((BRIDGE id)CFCreateSomething())]; +typedef int array1[sizeof((BRIDGE CFTypeRef)CreateSomething())]; diff --git a/test/SemaObjC/illegal-nonarc-bridged-cast.m b/test/SemaObjC/illegal-nonarc-bridged-cast.m index 04d82b9557..53613dcb44 100644 --- a/test/SemaObjC/illegal-nonarc-bridged-cast.m +++ b/test/SemaObjC/illegal-nonarc-bridged-cast.m @@ -16,19 +16,19 @@ id CreateSomething(); NSString *CreateNSString(); void from_cf() { - id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - (__bridge int*)CFCreateSomething(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} \ + id obj1 = (__bridge_transfer id)CFCreateSomething(); // expected-error {{bridge casts will have no effect in non-arc mode}} + id obj2 = (__bridge_transfer NSString*)CFCreateString(); // expected-error {{bridge casts will have no effect in non-arc mode}} + (__bridge int*)CFCreateSomething(); // expected-error {{bridge casts will have no effect in non-arc mode}} \ // expected-warning {{expression result unused}} - id obj3 = (__bridge id)CFGetSomething(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - id obj4 = (__bridge NSString*)CFGetString(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} + id obj3 = (__bridge id)CFGetSomething(); // expected-error {{bridge casts will have no effect in non-arc mode}} + id obj4 = (__bridge NSString*)CFGetString(); // expected-error {{bridge casts will have no effect in non-arc mode}} } void to_cf(id obj) { - CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} - CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); // expected-warning {{bridge casts will have no effect in non-arc mode and will be ignored}} + CFTypeRef cf1 = (__bridge_retained CFTypeRef)CreateSomething(); // expected-error {{bridge casts will have no effect in non-arc mode}} + CFStringRef cf2 = (__bridge_retained CFStringRef)CreateNSString(); // expected-error {{bridge casts will have no effect in non-arc mode}} + CFTypeRef cf3 = (__bridge CFTypeRef)CreateSomething(); // expected-error {{bridge casts will have no effect in non-arc mode}} + CFStringRef cf4 = (__bridge CFStringRef)CreateNSString(); // expected-error {{bridge casts will have no effect in non-arc mode}} } void fixits() { -- 2.40.0