diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-12-07 00:34:23 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-12-07 00:34:23 +0000 |
| commit | 1f0b3bfd75029463625643b1650e097afe227b5c (patch) | |
| tree | 455bc593d9918c54c6c7575676f74a8180802490 /clang/test/SemaObjC/objcbridge-related-attribute.m | |
| parent | 32c3f17d3655fa97817c697e8e2456e9283567ae (diff) | |
| download | bcm5719-llvm-1f0b3bfd75029463625643b1650e097afe227b5c.tar.gz bcm5719-llvm-1f0b3bfd75029463625643b1650e097afe227b5c.zip | |
ObjectiveC. Continuing implementation of objc_bridge_related
attribute in sema and issuing a variety of diagnostics lazily
for misuse of this attribute (and what to do) when converting
from CF types to ObjectiveC types (and vice versa).
// rdar://15499111
llvm-svn: 196629
Diffstat (limited to 'clang/test/SemaObjC/objcbridge-related-attribute.m')
| -rw-r--r-- | clang/test/SemaObjC/objcbridge-related-attribute.m | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/clang/test/SemaObjC/objcbridge-related-attribute.m b/clang/test/SemaObjC/objcbridge-related-attribute.m new file mode 100644 index 00000000000..bf6b4e7e359 --- /dev/null +++ b/clang/test/SemaObjC/objcbridge-related-attribute.m @@ -0,0 +1,41 @@ +// RUN: %clang_cc1 -fsyntax-only -x objective-c -verify -Wno-objc-root-class %s +// rdar://15499111 + +typedef struct __attribute__((objc_bridge_related(NSColor,colorWithCGColor:,CGColor))) CGColor *CGColorRef; // expected-note 5 {{declared here}} +typedef struct __attribute__((objc_bridge_related(NSColor,,CGColor1))) CGColor1 *CGColorRef1; // expected-note 3 {{declared here}} +typedef struct __attribute__((objc_bridge_related(NSColor,,))) CGColor2 *CGColorRef2; // expected-note 2 {{declared here}} + +@interface NSColor // expected-note 10 {{declared here}} ++ (NSColor *)colorWithCGColor:(CGColorRef)cgColor; +- (CGColorRef)CGColor; +- (CGColorRef1)CGColor1; +@end + +@interface NSTextField +- (void)setBackgroundColor:(NSColor *)color; +- (NSColor *)backgroundColor; +@end + +void foo(NSColor*); + +NSColor * Test1(NSTextField *textField, CGColorRef newColor) { + foo(newColor); // expected-error {{'CGColorRef' (aka 'struct CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}} + textField.backgroundColor = newColor; // expected-error {{'CGColorRef' (aka 'struct CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}} + return newColor; // expected-error {{'CGColorRef' (aka 'struct CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}} +} + +NSColor * Test2(NSTextField *textField, CGColorRef1 newColor) { + foo(newColor); // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') must be explicitly converted to 'NSColor *', define and then use a singular class method in NSColor for this conversion}} + textField.backgroundColor = newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') must be explicitly converted to 'NSColor *', define and then use a singular class method in NSColor for this conversion}} + return newColor; // expected-error {{'CGColorRef1' (aka 'struct CGColor1 *') must be explicitly converted to 'NSColor *', define and then use a singular class method in NSColor for this conversion}} +} + +CGColorRef Test3(NSTextField *textField, CGColorRef newColor) { + newColor = textField.backgroundColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'struct CGColor *'), use 'CGColor' method for this conversion}} + return textField.backgroundColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'struct CGColor *'), use 'CGColor' method for this conversion}} +} + +CGColorRef2 Test4(NSTextField *textField, CGColorRef2 newColor) { + newColor = textField.backgroundColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef2' (aka 'struct CGColor2 *'), define and then use an instance method in NSColor for this conversion}} + return textField.backgroundColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef2' (aka 'struct CGColor2 *'), define and then use an instance method in NSColor for this conversion}} +} |

