Index: cfe/trunk/lib/Sema/SemaExprObjC.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaExprObjC.cpp +++ cfe/trunk/lib/Sema/SemaExprObjC.cpp @@ -3355,7 +3355,7 @@ if (isAnyRetainable(TargetClass) && isAnyRetainable(SourceClass) && var && - var->getStorageClass() == SC_Extern && + !var->hasDefinition(Context) && var->getType().isConstQualified()) { // In system headers, they can also be assumed to be immune to retains. Index: cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm =================================================================== --- cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm +++ cfe/trunk/test/SemaObjCXX/arc-bridged-cast.mm @@ -52,3 +52,19 @@ ref = (__bridge_retained CFAnnotatedObjectRef) CreateSomething(); ref = (__bridge_retained CFAnnotatedObjectRef) CreateNSString(); } + +struct __CFAnnotatedObject { +} cf0; + +extern const CFAnnotatedObjectRef r0; +extern const CFAnnotatedObjectRef r1 = &cf0; +extern "C" const CFAnnotatedObjectRef r2; +extern "C" const CFAnnotatedObjectRef r3 = &cf0; + +void testExternC() { + id obj; + obj = (id)r0; + obj = (id)r1; // expected-error{{cast of C pointer type 'CFAnnotatedObjectRef' (aka 'const __CFAnnotatedObject *') to Objective-C pointer type 'id' requires a bridged cast}} expected-note{{use __bridge to convert directly}} expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFAnnotatedObjectRef'}} + obj = (id)r2; + obj = (id)r3; // expected-error{{cast of C pointer type 'CFAnnotatedObjectRef' (aka 'const __CFAnnotatedObject *') to Objective-C pointer type 'id' requires a bridged cast}} expected-note{{use __bridge to convert directly}} expected-note{{use __bridge_transfer to transfer ownership of a +1 'CFAnnotatedObjectRef'}} +}