/* Check for finding the prototype when there multiple conflicting available. */ /* Contributed by David Ayers and Alexander Malmberg */ /* { dg-do compile } */ #include typedef struct { unsigned long a1; } MyStruct1; typedef struct { unsigned long a1; } MyStruct2; typedef struct { unsigned long a1; } MyStruct3; typedef struct { unsigned long a1; } MyStruct4; typedef struct { unsigned long a1; } MyStruct5; typedef struct { unsigned long a1; } MyStruct6; typedef struct { unsigned long a1; } MyStruct7; typedef struct { unsigned long a1; } MyStruct8; typedef struct { unsigned long a1; } MyStruct9; typedef struct { unsigned long a1; } MyStruct10; typedef struct { unsigned long a1; } MyStruct11; /* Protocol from Inherited class declares method. */ @protocol Proto1 - (MyStruct1)getStruct1; @end /* Class declares method directly. */ @interface Class1 + (Class1 *)class1; - (MyStruct2)getStruct1; @end /* Protocol declares method. */ @protocol Proto2 - (MyStruct3)getStruct1; @end /* Superclass declares method. */ @interface Class2 : Class1 - (MyStruct4)getStruct1; @end @interface Class2 (Category1) - (MyStruct5)getStruct1; @end /* Category is inherited. */ @interface Class1 (Category2) - (MyStruct6)getStruct1; @end /* Category's protocol declares method. */ @protocol Proto3 - (MyStruct7)getStruct1; @end @interface Class2 (Category3) @end /* Inherited category's protocol declares method. */ @protocol Proto4 - (MyStruct8)getStruct1; @end @interface Class1 (Category4) @end @protocol Proto5 - (MyStruct9)getStruct1; @end /* Implicit local declaraions in class. */ @implementation Class2 -(MyStruct10)getStruct1 { /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class2." } */ /* { dg-warning "using .\\-\\(MyStruct4\\)getStruct1." "" { target *-*-* } 40 } */ /* { dg-warning "instead of .\\-\\(MyStruct7\\)getStruct1." "" { target *-*-* } 55 } */ /* { dg-warning "or .\\-\\(MyStruct5\\)getStruct1." "" { target *-*-* } 44 } */ /* { dg-warning "or .\\-\\(MyStruct3\\)getStruct1." "" { target *-*-* } 35 } */ /* { dg-warning "or .\\-\\(MyStruct2\\)getStruct1." "" { target *-*-* } 30 } */ /* { dg-warning "or .\\-\\(MyStruct8\\)getStruct1." "" { target *-*-* } 63 } */ /* { dg-warning "or .\\-\\(MyStruct6\\)getStruct1." "" { target *-*-* } 49 } */ /* { dg-warning "or .\\-\\(MyStruct1\\)getStruct1." "" { target *-*-* } 24 } */ MyStruct10 strct = { 1UL }; return strct; } -(void)useInInstance { MyStruct1 strct; strct = [self getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class2." } */ /* { dg-warning "or .\\-\\(MyStruct10\\)getStruct1." "" { target *-*-* } 76 } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 91 } */ } @end /* Implicit local declaraions in category. */ @implementation Class1 (Category5) -(MyStruct11)getStruct1 { /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-warning "using .\\-\\(MyStruct2\\)getStruct1." "" { target *-*-* } 30 } */ /* { dg-warning "instead of .\\-\\(MyStruct8\\)getStruct1." "" { target *-*-* } 63 } */ MyStruct11 strct = { 1UL }; return strct; } -(void)useInInstance2 { MyStruct1 strct; strct = [self getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-warning "or .\\-\\(MyStruct11\\)getStruct1." "" { target *-*-* } 101 } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 110 } */ } @end void foo1(void) { MyStruct1 strct; Class1 *varClass1; id varId; strct = [[Class1 class1] getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 122 } */ strct = [Class1 getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 125 } */ varClass1 = [Class1 class1]; strct = [varClass1 getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 129 } */ varId = [Class1 class1]; strct = [(Class1 *)varId getStruct1]; /* { dg-warning "multiple methods named .\\-getStruct1. found for receiver of type .Class1." } */ /* { dg-error "incompatible types in assignment" "" { target *-*-* } 134 } */ }