From f9aca2089e4322417be1523f720c25c43a620490 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 llvm-svn: 146918 --- .../clang/Basic/DiagnosticParseKinds.td | 5 ++--- clang/lib/Parse/ParseExpr.cpp | 2 +- clang/test/PCH/Inputs/arc.h | 10 ++++++++-- .../SemaObjC/illegal-nonarc-bridged-cast.m | 18 +++++++++--------- 4 files changed, 20 insertions(+), 15 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 7ce2a8e92860..7a3e0e6a71b5 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/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/clang/lib/Parse/ParseExpr.cpp b/clang/lib/Parse/ParseExpr.cpp index bb446f5ab232..bb26e28c122a 100644 --- a/clang/lib/Parse/ParseExpr.cpp +++ b/clang/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/clang/test/PCH/Inputs/arc.h b/clang/test/PCH/Inputs/arc.h index 793fc643f23c..304e612a0d91 100644 --- a/clang/test/PCH/Inputs/arc.h +++ b/clang/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/clang/test/SemaObjC/illegal-nonarc-bridged-cast.m b/clang/test/SemaObjC/illegal-nonarc-bridged-cast.m index 04d82b955778..53613dcb4457 100644 --- a/clang/test/SemaObjC/illegal-nonarc-bridged-cast.m +++ b/clang/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() {