diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fccbc56ce56..b9ce518dcac 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,12 @@ +Tue Sep 17 13:59:45 2002 Nicola Pero + + * objc.dg/comp-types-1.m: New test. + * objc.dg/comp-types-2.m: New test. + * objc.dg/comp-types-3.m: New test. + * objc.dg/comp-types-4.m: New test. + * objc.dg/comp-types-5.m: New test. + * objc.dg/comp-types-6.m: New test. + 2002-09-17 John David Anglin * gcc.c-torture/execute/strct-stdarg-1.x: Remove file. diff --git a/gcc/testsuite/objc.dg/comp-types-1.m b/gcc/testsuite/objc.dg/comp-types-1.m new file mode 100644 index 00000000000..74943860b2d --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-1.m @@ -0,0 +1,86 @@ +/* Test various ObjC types assignments and comparisons. */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocol +- (void) foo; +@end + +@interface MyClass +@end + +@interface MyOtherClass +- (void) foo; +@end + +int main() +{ + id obj = nil; + id obj_p = nil; + MyClass *obj_c = nil; + MyOtherClass *obj_cp = nil; + Class obj_C = Nil; + + /* Assigning to an 'id' variable should never + generate a warning. */ + obj = obj_p; /* Ok */ + obj = obj_c; /* Ok */ + obj = obj_cp; /* Ok */ + obj = obj_C; /* Ok */ + + /* Assigning to a 'MyClass *' variable should always generate a + warning, unless done from an 'id'. */ + obj_c = obj; /* Ok */ + obj_c = obj_p; /* { dg-warning "incompatible pointer type" } */ + obj_c = obj_cp; /* { dg-warning "incompatible pointer type" } */ + obj_c = obj_C; /* { dg-warning "incompatible pointer type" } */ + + /* Assigning to an 'id' variable should generate a + warning if done from a 'MyClass *' (which doesn't implement + MyProtocol), but not from an 'id' or from a 'MyOtherClass *' + (which implements MyProtocol). */ + obj_p = obj; /* Ok */ + obj_p = obj_c; /* { dg-warning "does not implement" } */ /*FIXME: Duplicated*/ + obj_p = obj_cp; /* Ok */ + obj_p = obj_C; /* { dg-warning "incompatible pointer type" } */ + + /* Assigning to a 'MyOtherClass *' variable should always generate + a warning, unless done from an 'id' */ + obj_cp = obj; /* Ok */ + obj_cp = obj_c; /* { dg-warning "incompatible pointer type" } */ + obj_cp = obj_p; /* { dg-warning "incompatible pointer type" } */ + obj_cp = obj_C; /* { dg-warning "incompatible pointer type" } */ + + /* Any comparison involving an 'id' must be without warnings. */ + if (obj == obj_p) ; /* Ok */ /*Bogus warning here in 2.95.4*/ + if (obj_p == obj) ; /* Ok */ + if (obj == obj_c) ; /* Ok */ + if (obj_c == obj) ; /* Ok */ + if (obj == obj_cp) ; /* Ok */ + if (obj_cp == obj) ; /* Ok */ + if (obj == obj_C) ; /* Ok */ + if (obj_C == obj) ; /* Ok */ + + /* Any comparison between 'MyClass *' and anything which is not an 'id' + must generate a warning. */ + if (obj_c == obj_p) ; /* { dg-warning "does not implement" } */ + if (obj_p == obj_c) ; /* { dg-warning "does not implement" } */ + if (obj_c == obj_cp) ; /* { dg-warning "lacks a cast" } */ + if (obj_cp == obj_c) ; /* { dg-warning "lacks a cast" } */ + if (obj_c == obj_C) ; /* { dg-warning "lacks a cast" } */ + if (obj_C == obj_c) ; /* { dg-warning "lacks a cast" } */ + + /* Any comparison between 'MyOtherClass *' (which implements + MyProtocol) and an 'id' implementing MyProtocol are Ok. */ + if (obj_cp == obj_p) ; /* Ok */ + if (obj_p == obj_cp) ; /* Ok */ + + + if (obj_p == obj_C) ; /* { dg-warning "lacks a cast" } */ + if (obj_C == obj_p) ; /* { dg-warning "lacks a cast" } */ + if (obj_cp == obj_C) ; /* { dg-warning "lacks a cast" } */ + if (obj_C == obj_cp) ; /* { dg-warning "lacks a cast" } */ + + return 0; +} diff --git a/gcc/testsuite/objc.dg/comp-types-2.m b/gcc/testsuite/objc.dg/comp-types-2.m new file mode 100644 index 00000000000..6e88df999b7 --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-2.m @@ -0,0 +1,37 @@ +/* Test simple ObjC types casts. */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocol +- (void) foo; +@end + +@interface MyClass +@end + +int main() +{ + id obj = nil; + id obj_p = nil; + MyClass *obj_c = nil; + Class obj_C = Nil; + + /* All these casts should generate no warnings. */ + + obj = (id)obj_p; + obj = (id)obj_c; + obj = (id)obj_C; + obj_c = (MyClass *)obj; + obj_c = (MyClass *)obj_p; + obj_c = (MyClass *)obj_C; + obj_p = (id)obj; + obj_p = (id)obj_c; + obj_p = (id)obj_C; + obj_C = (Class)obj; + obj_C = (Class)obj_p; + obj_C = (Class)obj_c; + + + return 0; +} diff --git a/gcc/testsuite/objc.dg/comp-types-3.m b/gcc/testsuite/objc.dg/comp-types-3.m new file mode 100644 index 00000000000..51f418ef529 --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-3.m @@ -0,0 +1,63 @@ +/* Test assignments and comparisons between protocols (obscure case). */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocolA +- (void) methodA; +@end + +@protocol MyProtocolB +- (void) methodB; +@end + +@protocol MyProtocolAB +@end + +@protocol MyProtocolAC +- (void) methodC; +@end + +int main() +{ + id obj_a = nil; + id obj_b = nil; + id obj_ab = nil; + id obj_ac = nil; + + obj_a = obj_b; /* { dg-warning "does not conform" } */ + obj_a = obj_ab; /* Ok */ + obj_a = obj_ac; /* Ok */ + + obj_b = obj_a; /* { dg-warning "does not conform" } */ + obj_b = obj_ab; /* Ok */ + obj_b = obj_ac; /* { dg-warning "does not conform" } */ + + obj_ab = obj_a; /* { dg-warning "does not conform" } */ + obj_ab = obj_b; /* { dg-warning "does not conform" } */ + obj_ab = obj_ac; /* { dg-warning "does not conform" } */ + + obj_ac = obj_a; /* { dg-warning "does not conform" } */ + obj_ac = obj_b; /* { dg-warning "does not conform" } */ + obj_ac = obj_ab; /* { dg-warning "does not conform" } */ + + if (obj_a == obj_b) ; /* { dg-warning "lacks a cast" } */ + if (obj_b == obj_a) ; /* { dg-warning "lacks a cast" } */ + + if (obj_a == obj_ab) ; /* Ok */ + if (obj_ab == obj_a) ; /* Ok */ /* Spurious 2.95.4 warning here */ + + if (obj_a == obj_ac) ; /* Ok */ + if (obj_ac == obj_a) ; /* Ok */ /* Spurious 2.95.4 warning here */ + + if (obj_b == obj_ab) ; /* Ok */ + if (obj_ab == obj_b) ; /* Ok */ /* Spurious 2.95.4 warning here */ + + if (obj_b == obj_ac) ; /* { dg-warning "lacks a cast" } */ + if (obj_ac == obj_b) ; /* { dg-warning "lacks a cast" } */ + + if (obj_ab == obj_ac) ; /* { dg-warning "lacks a cast" } */ + if (obj_ac == obj_ab) ; /* { dg-warning "lacks a cast" } */ + + return 0; +} diff --git a/gcc/testsuite/objc.dg/comp-types-4.m b/gcc/testsuite/objc.dg/comp-types-4.m new file mode 100644 index 00000000000..e07780485ee --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-4.m @@ -0,0 +1,68 @@ +/* Test warnings for assignments and comparisons between ObjC and C types. */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocol +- (void) method; +@end + +@interface MyClass +@end + +int main() +{ + id obj = nil; + id obj_p = nil; + MyClass *obj_c = nil; + Class obj_C = Nil; + + int i = 0; + int *j = NULL; + + /* These should all generate warnings. */ + + obj = i; /* { dg-warning "pointer from integer without a cast" } */ + obj = j; /* { dg-warning "incompatible pointer type" } */ + + obj_p = i; /* { dg-warning "pointer from integer without a cast" } */ + obj_p = j; /* { dg-warning "incompatible pointer type" } */ + + obj_c = i; /* { dg-warning "pointer from integer without a cast" } */ + obj_c = j; /* { dg-warning "incompatible pointer type" } */ + + obj_C = i; /* { dg-warning "pointer from integer without a cast" } */ + obj_C = j; /* { dg-warning "incompatible pointer type" } */ + + i = obj; /* { dg-warning "integer from pointer without a cast" } */ + i = obj_p; /* { dg-warning "integer from pointer without a cast" } */ + i = obj_c; /* { dg-warning "integer from pointer without a cast" } */ + i = obj_C; /* { dg-warning "integer from pointer without a cast" } */ + + j = obj; /* { dg-warning "incompatible pointer type" } */ + j = obj_p; /* { dg-warning "incompatible pointer type" } */ + j = obj_c; /* { dg-warning "incompatible pointer type" } */ + j = obj_C; /* { dg-warning "incompatible pointer type" } */ + + if (obj == i) ; /* { dg-warning "comparison between pointer and integer" } */ + if (i == obj) ; /* { dg-warning "comparison between pointer and integer" } */ + if (obj == j) ; /* { dg-warning "lacks a cast" } */ + if (j == obj) ; /* { dg-warning "lacks a cast" } */ + + if (obj_c == i) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (i == obj_c) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (obj_c == j) ; /* { dg-warning "lacks a cast" } */ + if (j == obj_c) ; /* { dg-warning "lacks a cast" } */ + + if (obj_p == i) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (i == obj_p) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (obj_p == j) ; /* { dg-warning "lacks a cast" } */ + if (j == obj_p) ; /* { dg-warning "lacks a cast" } */ + + if (obj_C == i) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (i == obj_C) ; /*{ dg-warning "comparison between pointer and integer" }*/ + if (obj_C == j) ; /* { dg-warning "lacks a cast" } */ + if (j == obj_C) ; /* { dg-warning "lacks a cast" } */ + + return 0; +} diff --git a/gcc/testsuite/objc.dg/comp-types-5.m b/gcc/testsuite/objc.dg/comp-types-5.m new file mode 100644 index 00000000000..f4d3dfc94e9 --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-5.m @@ -0,0 +1,32 @@ +/* Test assignments and comparisons involving `one-off' protocols. */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocol +- (void) method; +@end + +@interface MyClass +@end + +int main() +{ + id obj = nil; + id obj_p = nil; + MyClass *obj_cp = nil; + + obj_cp = obj; /* Ok */ + obj = obj_cp; /* Ok */ + + obj_cp = obj_p; /* { dg-warning "incompatible pointer type" } */ + obj_p = obj_cp; /* Ok */ /* Spurious 2.95.4 warning here. */ + + if (obj_cp == obj) ; /* Ok */ + if (obj == obj_cp) ; /* Ok */ + + if (obj_cp == obj_p) ; /* Ok */ + if (obj_p == obj_cp) ; /* Ok */ + + return 0; +} diff --git a/gcc/testsuite/objc.dg/comp-types-6.m b/gcc/testsuite/objc.dg/comp-types-6.m new file mode 100644 index 00000000000..9403b532fd3 --- /dev/null +++ b/gcc/testsuite/objc.dg/comp-types-6.m @@ -0,0 +1,37 @@ +/* Test assignments and comparisons involving category protocols. */ +/* Author: Nicola Pero . */ +/* { dg-do compile } */ +#include + +@protocol MyProtocol +- (void) method; +@end + +@interface MyClass +@end + +@interface MyClass (Addition) +- (void) method; +@end + +@interface MyOtherClass : MyClass +@end + +int main() +{ + id obj_p = nil; + MyClass *obj_cp = nil; + MyOtherClass *obj_cp2 = nil; + + obj_cp = obj_p; /* { dg-warning "incompatible pointer type" } */ + obj_cp2 = obj_p; /* { dg-warning "incompatible pointer type" } */ + obj_p = obj_cp; /* Ok */ + obj_p = obj_cp2; /* Ok */ + + if (obj_cp == obj_p) ; /* Ok */ + if (obj_cp2 == obj_p) ; /* Ok */ + if (obj_p == obj_cp) ; /* Ok */ + if (obj_p == obj_cp2) ; /* Ok */ + + return 0; +}