New tests for ObjC typechecking
From-SVN: r57251
This commit is contained in:
parent
1074d9d492
commit
ff2522a5c9
@ -1,3 +1,12 @@
|
||||
Tue Sep 17 13:59:45 2002 Nicola Pero <n.pero@mi.flashnet.it>
|
||||
|
||||
* 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 <dave@hiauly1.hia.nrc.ca>
|
||||
|
||||
* gcc.c-torture/execute/strct-stdarg-1.x: Remove file.
|
||||
|
86
gcc/testsuite/objc.dg/comp-types-1.m
Normal file
86
gcc/testsuite/objc.dg/comp-types-1.m
Normal file
@ -0,0 +1,86 @@
|
||||
/* Test various ObjC types assignments and comparisons. */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocol
|
||||
- (void) foo;
|
||||
@end
|
||||
|
||||
@interface MyClass
|
||||
@end
|
||||
|
||||
@interface MyOtherClass <MyProtocol>
|
||||
- (void) foo;
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id obj = nil;
|
||||
id<MyProtocol> 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<MyProtocol>' 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;
|
||||
}
|
37
gcc/testsuite/objc.dg/comp-types-2.m
Normal file
37
gcc/testsuite/objc.dg/comp-types-2.m
Normal file
@ -0,0 +1,37 @@
|
||||
/* Test simple ObjC types casts. */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocol
|
||||
- (void) foo;
|
||||
@end
|
||||
|
||||
@interface MyClass
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id obj = nil;
|
||||
id<MyProtocol> 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<MyProtocol>)obj;
|
||||
obj_p = (id<MyProtocol>)obj_c;
|
||||
obj_p = (id<MyProtocol>)obj_C;
|
||||
obj_C = (Class)obj;
|
||||
obj_C = (Class)obj_p;
|
||||
obj_C = (Class)obj_c;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
63
gcc/testsuite/objc.dg/comp-types-3.m
Normal file
63
gcc/testsuite/objc.dg/comp-types-3.m
Normal file
@ -0,0 +1,63 @@
|
||||
/* Test assignments and comparisons between protocols (obscure case). */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocolA
|
||||
- (void) methodA;
|
||||
@end
|
||||
|
||||
@protocol MyProtocolB
|
||||
- (void) methodB;
|
||||
@end
|
||||
|
||||
@protocol MyProtocolAB <MyProtocolA, MyProtocolB>
|
||||
@end
|
||||
|
||||
@protocol MyProtocolAC <MyProtocolA>
|
||||
- (void) methodC;
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id<MyProtocolA> obj_a = nil;
|
||||
id<MyProtocolB> obj_b = nil;
|
||||
id<MyProtocolAB> obj_ab = nil;
|
||||
id<MyProtocolAC> 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;
|
||||
}
|
68
gcc/testsuite/objc.dg/comp-types-4.m
Normal file
68
gcc/testsuite/objc.dg/comp-types-4.m
Normal file
@ -0,0 +1,68 @@
|
||||
/* Test warnings for assignments and comparisons between ObjC and C types. */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocol
|
||||
- (void) method;
|
||||
@end
|
||||
|
||||
@interface MyClass
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id obj = nil;
|
||||
id <MyProtocol> 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;
|
||||
}
|
32
gcc/testsuite/objc.dg/comp-types-5.m
Normal file
32
gcc/testsuite/objc.dg/comp-types-5.m
Normal file
@ -0,0 +1,32 @@
|
||||
/* Test assignments and comparisons involving `one-off' protocols. */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocol
|
||||
- (void) method;
|
||||
@end
|
||||
|
||||
@interface MyClass
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id obj = nil;
|
||||
id <MyProtocol> obj_p = nil;
|
||||
MyClass<MyProtocol> *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;
|
||||
}
|
37
gcc/testsuite/objc.dg/comp-types-6.m
Normal file
37
gcc/testsuite/objc.dg/comp-types-6.m
Normal file
@ -0,0 +1,37 @@
|
||||
/* Test assignments and comparisons involving category protocols. */
|
||||
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */
|
||||
/* { dg-do compile } */
|
||||
#include <objc/objc.h>
|
||||
|
||||
@protocol MyProtocol
|
||||
- (void) method;
|
||||
@end
|
||||
|
||||
@interface MyClass
|
||||
@end
|
||||
|
||||
@interface MyClass (Addition) <MyProtocol>
|
||||
- (void) method;
|
||||
@end
|
||||
|
||||
@interface MyOtherClass : MyClass
|
||||
@end
|
||||
|
||||
int main()
|
||||
{
|
||||
id <MyProtocol> 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user