208 lines · plain
1// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks -Wno-strict-prototypes %s2 3#define SWIFT_NAME(name) __attribute__((__swift_name__(name)))4#define SWIFT_ASYNC_NAME(name) __attribute__((__swift_async_name__(name)))5 6typedef struct {7 float x, y, z;8} Point3D;9 10__attribute__((__swift_name__("PType")))11@protocol P12@end13 14__attribute__((__swift_name__("IClass")))15@interface I<P>16- (instancetype)init SWIFT_NAME("init()");17- (instancetype)initWithValue:(int)value SWIFT_NAME("iWithValue(_:)");18 19+ (void)refresh SWIFT_NAME("refresh()");20 21- (instancetype)i SWIFT_NAME("i()");22 23- (I *)iWithValue:(int)value SWIFT_NAME("i(value:)");24- (I *)iWithValue:(int)value value:(int)value2 SWIFT_NAME("i(value:extra:)");25- (I *)iWithValueConvertingValue:(int)value value:(int)value2 SWIFT_NAME("i(_:extra:)");26 27+ (I *)iWithOtheValue:(int)value SWIFT_NAME("init");28// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}29 30+ (I *)iWithAnotherValue:(int)value SWIFT_NAME("i()");31// expected-warning@-1 {{too few parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 0)}}32 33+ (I *)iWithYetAnotherValue:(int)value SWIFT_NAME("i(value:extra:)");34// expected-warning@-1 {{too many parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 2}}35 36+ (I *)iAndReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning37+ (I *)iWithValue:(int)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(value:)"); // no-warning38 39+ (I *)iFromErrorCode:(const int *)errorCode SWIFT_NAME("i()");40// expected-warning@-1 {{too few parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 0)}}41 42+ (I *)iWithPointerA:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i()"); // no-warning43+ (I *)iWithPointerB:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:)"); // no-warning44+ (I *)iWithPointerC:(int *)value andReturnErrorCode:(int *)errorCode SWIFT_NAME("i(pointer:errorCode:)"); // no-warning45 46+ (I *)iWithOtherI:(I *)other SWIFT_NAME("i()");47// expected-warning@-1 {{too few parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 0)}}48 49+ (instancetype)specialI SWIFT_NAME("init(options:)");50+ (instancetype)specialJ SWIFT_NAME("init(options:extra:)");51// expected-warning@-1 {{too many parameters in the signature specified by the '__swift_name__' attribute (expected 0; got 2)}}52+ (instancetype)specialK SWIFT_NAME("init(_:)");53// expected-warning@-1 {{too many parameters in the signature specified by the '__swift_name__' attribute (expected 0; got 1)}}54+ (instancetype)specialL SWIFT_NAME("i(options:)");55// expected-warning@-1 {{too many parameters in the signature specified by the '__swift_name__' attribute (expected 0; got 1)}}56 57+ (instancetype)trailingParen SWIFT_NAME("foo(");58// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}59+ (instancetype)trailingColon SWIFT_NAME("foo:");60// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}61+ (instancetype)emptyString SWIFT_NAME("");62// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}63+ (instancetype)initialIgnore:(int)value SWIFT_NAME("_(value:)");64// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for the base name}}65+ (instancetype)middleOmitted:(int)value SWIFT_NAME("i(:)");66// expected-warning@-1 {{'__swift_name__' attribute has invalid identifier for the parameter name}}67 68@property(strong) id someProp SWIFT_NAME("prop");69@end70 71enum SWIFT_NAME("E") E {72 value1,73 value2,74 value3 SWIFT_NAME("three"),75 value4 SWIFT_NAME("four()"), // expected-warning {{'__swift_name__' attribute has invalid identifier for the base name}}76};77 78struct SWIFT_NAME("TStruct") SStruct {79 int i, j, k SWIFT_NAME("kay");80};81 82int i SWIFT_NAME("g_i");83 84void f0(int i) SWIFT_NAME("f_0");85// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}86 87void f1(int i) SWIFT_NAME("f_1()");88// expected-warning@-1 {{too few parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 0)}}89 90void f2(int i) SWIFT_NAME("f_2(a:b:)");91// expected-warning@-1 {{too many parameters in the signature specified by the '__swift_name__' attribute (expected 1; got 2)}}92 93void f3(int x, int y) SWIFT_NAME("fWithX(_:y:)");94void f4(int x, int *error) SWIFT_NAME("fWithX(_:)");95 96typedef int int_t SWIFT_NAME("IntType");97 98struct Point3D createPoint3D(float x, float y, float z) SWIFT_NAME("Point3D.init(x:y:z:)");99struct Point3D rotatePoint3D(Point3D point, float radians) SWIFT_NAME("Point3D.rotate(self:radians:)");100struct Point3D badRotatePoint3D(Point3D point, float radians) SWIFT_NAME("Point3D.rotate(radians:)");101// expected-warning@-1 {{too few parameters in the signature specified by the '__swift_name__' attribute (expected 2; got 1)}}102 103extern struct Point3D identityPoint SWIFT_NAME("Point3D.identity");104 105float Point3DGetMagnitude(Point3D point) SWIFT_NAME("getter:Point3D.magnitude(self:)");106float Point3DGetMagnitudeAndSomethingElse(Point3D point, float f) SWIFT_NAME("getter:Point3D.magnitude(self:f:)");107// expected-warning@-1 {{'__swift_name__' attribute for getter must not have any parameters besides 'self:'}}108 109float Point3DGetRadius(Point3D point) SWIFT_NAME("getter:Point3D.radius(self:)");110void Point3DSetRadius(Point3D point, float radius) SWIFT_NAME("setter:Point3D.radius(self:newValue:)");111 112float Point3DPreGetRadius(Point3D point) SWIFT_NAME("getter:Point3D.preRadius(self:)");113void Point3DPreSetRadius(float radius, Point3D point) SWIFT_NAME("setter:Point3D.preRadius(newValue:self:)");114 115void Point3DSetRadiusAndSomethingElse(Point3D point, float radius, float f) SWIFT_NAME("setter:Point3D.radius(self:newValue:f:)");116// expected-warning@-1 {{'__swift_name__' attribute for setter must have one parameter for new value}}117 118float Point3DGetComponent(Point3D point, unsigned index) SWIFT_NAME("getter:Point3D.subscript(self:_:)");119float Point3DSetComponent(Point3D point, unsigned index, float value) SWIFT_NAME("setter:Point3D.subscript(self:_:newValue:)");120 121float Point3DGetMatrixComponent(Point3D point, unsigned x, unsigned y) SWIFT_NAME("getter:Point3D.subscript(self:x:y:)");122void Point3DSetMatrixComponent(Point3D point, unsigned x, float value, unsigned y) SWIFT_NAME("setter:Point3D.subscript(self:x:newValue:y:)");123 124float Point3DSetWithoutNewValue(Point3D point, unsigned x, unsigned y) SWIFT_NAME("setter:Point3D.subscript(self:x:y:)");125// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' setter must have a 'newValue:' parameter}}126 127float Point3DSubscriptButNotGetterSetter(Point3D point, unsigned x) SWIFT_NAME("Point3D.subscript(self:_:)");128// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' must be a getter or setter}}129 130void Point3DSubscriptSetterTwoNewValues(Point3D point, unsigned x, float a, float b) SWIFT_NAME("setter:Point3D.subscript(self:_:newValue:newValue:)");131// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' setter cannot have multiple 'newValue:' parameters}}132 133float Point3DSubscriptGetterNewValue(Point3D point, unsigned x, float a, float b) SWIFT_NAME("getter:Point3D.subscript(self:_:newValue:newValue:)");134// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' getter cannot have a 'newValue:' parameter}}135 136void Point3DMethodWithNewValue(Point3D point, float newValue) SWIFT_NAME("Point3D.method(self:newValue:)");137void Point3DMethodWithNewValues(Point3D point, float newValue, float newValueB) SWIFT_NAME("Point3D.method(self:newValue:newValue:)");138 139float Point3DStaticSubscript(unsigned x) SWIFT_NAME("getter:Point3D.subscript(_:)");140// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' must have a 'self:' parameter}}141 142float Point3DStaticSubscriptNoArgs(void) SWIFT_NAME("getter:Point3D.subscript()");143// expected-warning@-1 {{'__swift_name__' attribute for 'subscript' must have at least one parameter}}144 145float Point3DPreGetComponent(Point3D point, unsigned index) SWIFT_NAME("getter:Point3D.subscript(self:_:)");146 147Point3D getCurrentPoint3D(void) SWIFT_NAME("getter:currentPoint3D()");148 149void setCurrentPoint3D(Point3D point) SWIFT_NAME("setter:currentPoint3D(newValue:)");150 151Point3D getLastPoint3D(void) SWIFT_NAME("getter:lastPoint3D()");152 153void setLastPoint3D(Point3D point) SWIFT_NAME("setter:lastPoint3D(newValue:)");154 155Point3D getZeroPoint(void) SWIFT_NAME("getter:Point3D.zero()");156void setZeroPoint(Point3D point) SWIFT_NAME("setter:Point3D.zero(newValue:)");157Point3D getZeroPointNoPrototype() SWIFT_NAME("getter:Point3D.zeroNoPrototype()");158// expected-warning@-1 {{'__swift_name__' attribute only applies to non-K&R-style functions}}159 160Point3D badGetter1(int x) SWIFT_NAME("getter:bad1(_:)");161// expected-warning@-1 {{'__swift_name__' attribute for getter must not have any parameters besides 'self:'}}162 163void badSetter1(void) SWIFT_NAME("getter:bad1())");164// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}165 166Point3D badGetter2(Point3D point) SWIFT_NAME("getter:bad2(_:))");167// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}168 169void badSetter2(Point3D point) SWIFT_NAME("setter:bad2(self:))");170// expected-warning@-1 {{'__swift_name__' attribute argument must be a string literal specifying a Swift function name}}171 172void g(int i) SWIFT_NAME("function(int:)");173// expected-note@-1 {{conflicting attribute is here}}174 175// expected-error@+1 {{'swift_name' and 'swift_name' attributes are not compatible}}176void g(int i) SWIFT_NAME("function(_:)") {177}178 179typedef int (^CallbackTy)(void);180 181@interface AsyncI<P>182 183- (void)doSomethingWithCallback:(CallbackTy)callback SWIFT_ASYNC_NAME("doSomething()");184- (void)doSomethingX:(int)x withCallback:(CallbackTy)callback SWIFT_ASYNC_NAME("doSomething(x:)");185 186// expected-warning@+1 {{too many parameters in the signature specified by the '__swift_async_name__' attribute (expected 1; got 2)}}187- (void)doSomethingY:(int)x withCallback:(CallbackTy)callback SWIFT_ASYNC_NAME("doSomething(x:y:)");188 189// expected-warning@+1 {{too few parameters in the signature specified by the '__swift_async_name__' attribute (expected 1; got 0)}}190- (void)doSomethingZ:(int)x withCallback:(CallbackTy)callback SWIFT_ASYNC_NAME("doSomething()");191 192// expected-warning@+1 {{'__swift_async_name__' attribute cannot be applied to a method with no parameters}}193- (void)doSomethingNone SWIFT_ASYNC_NAME("doSomething()");194 195// expected-error@+1 {{'__swift_async_name__' attribute takes one argument}}196- (void)brokenAttr __attribute__((__swift_async_name__("brokenAttr", 2)));197 198@end199 200void asyncFunc(CallbackTy callback) SWIFT_ASYNC_NAME("asyncFunc()");201 202// expected-warning@+1 {{'__swift_async_name__' attribute cannot be applied to a function with no parameters}}203void asyncNoParams(void) SWIFT_ASYNC_NAME("asyncNoParams()");204 205// expected-error@+1 {{'__swift_async_name__' attribute only applies to Objective-C methods and functions}}206SWIFT_ASYNC_NAME("NoAsync")207@protocol NoAsync @end208