[cfe-dev] Obj-C Retain Property Issues

Eli Friedman eli.friedman at gmail.com
Thu Dec 15 20:29:35 PST 2011


On Thu, Dec 15, 2011 at 2:37 PM, Keaton Mowery <kmowery at ucsd.edu> wrote:
> Hi all,
>
> I'm encountering an issue with LLVM/Clang's handling of Objective-C
> properties. Notably, adding the retain property to a non-NSObject is
> failing, even when the retain property can still be applied. Here's a
> minimal testcase:
>
> main.m
> ------------------
> #import <Foundation/Foundation.h>
>
> @interface Foo : NSObject {
>  CFDictionaryRef dict;
> }
> @property (nonatomic, retain) __attribute__((NSObject)) CFDictionaryRef dict;

I don't believe this was ever intentionally supported;

> @end
> @implementation Foo @synthesize dict; @end
> ------------------
>
> When compiled via llvm/clang (svn r146687), this generates an error:
>    main.m:7:1: error: property with 'retain (or strong)' attribute
> must be of object type
>    @property (nonatomic, retain) __attribute__((NSObject))
> CFDictionaryRef dict;
>
> When using the clang shipped with OSX (Apple clang version 3.0
> (tags/Apple/clang-211.12) (based on LLVM 3.0svn)), this compiles
> properly.
>
> The issue crops up when including the system header at
> /System/Library/Frameworks/AVFoundation.framework/Headers/AVVideoComposition.h:112,
> which leads me to believe that this is proper Objective-C syntax.
>
> Does anyone know what the problem might be?

__attribute__((NSObject)) was only ever intended to be used on
typedefs, and even that usage is not recommended.

That said, I'm pretty sure r145358 was not intended to break anything.
 I've opened an Apple-internal bug report to track the issue
(<rdar://problem/10591336>).

-Eli




More information about the cfe-dev mailing list