[LLVMbugs] [Bug 8704] New: LLVM/Clang unexpectedly generates ivar for readonly properties

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Nov 29 17:31:56 PST 2010


http://llvm.org/bugs/show_bug.cgi?id=8704

           Summary: LLVM/Clang unexpectedly generates ivar for readonly
                    properties
           Product: clang
           Version: unspecified
          Platform: Macintosh
        OS/Version: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: nfarina at gmail.com
                CC: llvmbugs at cs.uiuc.edu


I'm using the new iOS 4.2 SDK and LLVM 1.6, and I've been trying the new
"@synthesize by default" feature which is _awesome_. (using -Xclang and
-fobjc-nonfragile-abi2)

However I've noticed an odd side effect: Clang seems to be "automatically
synthesizing" and declaring ivars for readonly properties for which I've
defined a "getter" method.

Example Object:

@interface TestObject : NSObject
@property (nonatomic, readonly) NSString *hello;
@end

@implementation TestObject
- (NSString *) hello { return @"world."; }
@end

Later, when inspecting the class:

    unsigned int varCount;

    Ivar *vars = class_copyIvarList([TestObject class], &varCount);

    for (int i = 0; i < varCount; i++) {
        Ivar var = vars[i];

        const char* name = ivar_getName(var);
        const char* typeEncoding = ivar_getTypeEncoding(var);

        NSLog(@"IVAR %s of type %s", name, typeEncoding);
    }

    free(vars);

Prints: IVAR hello of type @"NSString"

The problem goes away if I explicitly declare "@dynamic hello". But this seems
unnecessary: I can't imagine a case where I would want a readonly property with
an automatic ivar where I've *also* created my own getter method.

Appreciate all your guys' work on these amazing new features!

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list