summaryrefslogtreecommitdiffstats
path: root/clang/test/SemaObjCXX/objcbridge-related-attribute.mm
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2013-12-07 00:34:23 +0000
committerFariborz Jahanian <fjahanian@apple.com>2013-12-07 00:34:23 +0000
commit1f0b3bfd75029463625643b1650e097afe227b5c (patch)
tree455bc593d9918c54c6c7575676f74a8180802490 /clang/test/SemaObjCXX/objcbridge-related-attribute.mm
parent32c3f17d3655fa97817c697e8e2456e9283567ae (diff)
downloadbcm5719-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/SemaObjCXX/objcbridge-related-attribute.mm')
-rw-r--r--clang/test/SemaObjCXX/objcbridge-related-attribute.mm31
1 files changed, 31 insertions, 0 deletions
diff --git a/clang/test/SemaObjCXX/objcbridge-related-attribute.mm b/clang/test/SemaObjCXX/objcbridge-related-attribute.mm
new file mode 100644
index 00000000000..787e94081d7
--- /dev/null
+++ b/clang/test/SemaObjCXX/objcbridge-related-attribute.mm
@@ -0,0 +1,31 @@
+// 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 6 {{declared here}}
+
+@interface NSColor // expected-note 6 {{declared here}}
++ (NSColor *)colorWithCGColor:(CGColorRef)cgColor;
+- (CGColorRef)CGColor;
+@end
+
+@interface NSTextField
+- (void)setBackgroundColor:(NSColor *)color;
+- (NSColor *)backgroundColor;
+@end
+
+
+NSColor *Test1(NSColor *nsColor, CGColorRef newColor) {
+ nsColor = newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}}
+ NSColor *ns = newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}} \
+ // expected-error {{cannot initialize a variable of type 'NSColor *' with an lvalue of type 'CGColorRef' (aka 'CGColor *')}}
+ return newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *', use 'colorWithCGColor:' method for this conversion}} \
+ // expected-error {{cannot initialize return object of type 'NSColor *' with an lvalue of type 'CGColorRef' (aka 'CGColor *')}}
+}
+
+CGColorRef Test2(NSColor *newColor, CGColorRef cgColor) {
+ cgColor = newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'), use 'CGColor' method for this conversion}}
+ CGColorRef cg = newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'), use 'CGColor' method for this conversion}} \
+ // expected-error {{cannot initialize a variable of type 'CGColorRef' (aka 'CGColor *') with an lvalue of type 'NSColor *'}}
+ return newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'), use 'CGColor' method for this conversion}}\
+ // expected-error {{cannot initialize return object of type 'CGColorRef' (aka 'CGColor *') with an lvalue of type 'NSColor *'}}
+}
+
OpenPOWER on IntegriCloud