これは GCC 4.2 フロントエンドのバグであり、LLVM-GCC 4.2 でも再現可能です。おめでとう!これらのコンパイラでは、割り当てられる値が条件演算子の結果の式である場合、ドット構文を使用したプロパティの割り当てに問題があります。
次のコードは問題を再現し、2 つのソース コード ソリューションを示しています。もう 1 つの解決策は、ドット構文ではなく、従来の Objective-C メッセージ送信構文を使用することです。
#import <Foundation/Foundation.h>
CGRect CGRectFromString(NSString *string);
@interface SomeClass : NSObject
@property (nonatomic, assign) CGRect frame;
@end
@implementation SomeClass
@synthesize frame;
@end
int main(void) {
NSDictionary *info;
SomeClass *interaction;
NSString *kInteractionFrameKey;
CGRect rect;
rect = [info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero;
interaction.frame = rect;
[interaction setFrame:([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero)];
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectFromString([info objectForKey:kInteractionFrameKey]) : CGRectZero);
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectZero : CGRectFromString([info objectForKey:kInteractionFrameKey]));
interaction.frame = ([info objectForKey:kInteractionFrameKey] ? CGRectZero : CGRectZero);
return 0;
}
さまざまなコンパイラでテストすると、次の結果が得られます。
$ llvm-gcc -c test.m
test.m: In function ‘main’:
test.m:24: error: assignment of read-only variable ‘prop.76’
test.m:25: error: assignment of read-only variable ‘prop.77’
test.m:26: error: assignment of read-only variable ‘prop.78’
$ clang -c test.m
$
その特定のケースでは、LLVM を使用するか、ドット構文を避けることができます。バグを報告したくなるかもしれませんが、Apple が GCC を更新する可能性は低いので、息を止めません。