xref: /llvm-project/clang/test/SemaObjCXX/objcbridge-related-attribute.mm (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -fsyntax-only -x objective-c++ -verify -Wno-objc-root-class %s
2typedef struct __attribute__((objc_bridge_related(NSColor,colorWithCGColor:,CGColor))) CGColor *CGColorRef; // expected-note 6 {{declared here}}
3
4@interface NSColor // expected-note 6 {{declared here}}
5+ (NSColor *)colorWithCGColor:(CGColorRef)cgColor;
6- (CGColorRef)CGColor;
7@end
8
9@interface NSTextField
10- (void)setBackgroundColor:(NSColor *)color;
11- (NSColor *)backgroundColor;
12@end
13
14
15NSColor *Test1(NSColor *nsColor, CGColorRef newColor) {
16  nsColor = newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *'; use '+colorWithCGColor:' method for this conversion}}
17  NSColor *ns = newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *'; use '+colorWithCGColor:' method for this conversion}}
18  return newColor; // expected-error {{'CGColorRef' (aka 'CGColor *') must be explicitly converted to 'NSColor *'; use '+colorWithCGColor:' method for this conversion}}
19}
20
21CGColorRef Test2(NSColor *newColor, CGColorRef cgColor) {
22  cgColor = newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'); use '-CGColor' method for this conversion}}
23  CGColorRef cg = newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'); use '-CGColor' method for this conversion}}
24  return newColor; // expected-error {{'NSColor *' must be explicitly converted to 'CGColorRef' (aka 'CGColor *'); use '-CGColor' method for this conversion}}
25}
26
27