URL
https://opencores.org/ocsvn/openrisc/openrisc/trunk
Subversion Repositories openrisc
Compare Revisions
- This comparison shows the changes necessary to convert path
/openrisc/trunk/gnu-old/gcc-4.2.2/gcc/testsuite/obj-c++.dg
- from Rev 154 to Rev 816
- ↔ Reverse comparison
Rev 154 → Rev 816
/method-19.mm
0,0 → 1,80
/* Test if instance methods of root classes are used as class methods, if no |
"real" methods are found. For receivers of type 'id' and 'Class', all |
root classes must be considered. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do run } */ |
|
#include <objc/objc.h> |
|
#ifdef __NEXT_RUNTIME__ |
#include <objc/objc-runtime.h> |
#define OBJC_GETCLASS objc_getClass |
#else |
#include <objc/objc-api.h> |
#define OBJC_GETCLASS objc_get_class |
#endif |
|
#include <stdlib.h> |
#include <string.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@protocol Proto |
- (const char *) method4; |
@end |
|
@interface Root |
{ Class isa; } |
+ (const char *) method2; |
@end |
|
@interface Derived: Root |
- (const char *) method1; |
- (const char *) method2; |
- (const char *) method3; |
@end |
|
@interface Root (Categ) |
- (const char *) method3; |
@end |
|
@implementation Root (Categ) |
- (const char *) method3 { return "Root(Categ)::-method3"; } |
- (const char *) method4 { return "Root(Categ)::-method4"; } |
@end |
|
@implementation Derived |
- (const char *) method1 { return "Derived::-method1"; } |
- (const char *) method2 { return "Derived::-method2"; } |
- (const char *) method3 { return "Derived::-method3"; } |
@end |
|
@implementation Root |
#ifdef __NEXT_RUNTIME__ |
+ initialize { return self; } |
#endif |
- (const char *) method1 { return "Root::-method1"; } |
+ (const char *) method2 { return "Root::+method2"; } |
@end |
|
int main(void) |
{ |
Class obj = OBJC_GETCLASS("Derived"); |
|
/* None of the following should elicit compiler-time warnings. */ |
|
CHECK_IF(!strcmp([Root method1], "Root::-method1")); |
CHECK_IF(!strcmp([Root method2], "Root::+method2")); |
CHECK_IF(!strcmp([Root method3], "Root(Categ)::-method3")); |
CHECK_IF(!strcmp([Root method4], "Root(Categ)::-method4")); |
CHECK_IF(!strcmp([Derived method1], "Root::-method1")); |
CHECK_IF(!strcmp([Derived method2], "Root::+method2")); |
CHECK_IF(!strcmp([Derived method3], "Root(Categ)::-method3")); |
CHECK_IF(!strcmp([Derived method4], "Root(Categ)::-method4")); |
CHECK_IF(!strcmp([obj method1], "Root::-method1")); |
CHECK_IF(!strcmp([obj method2], "Root::+method2")); |
CHECK_IF(!strcmp([obj method3], "Root(Categ)::-method3")); |
CHECK_IF(!strcmp([obj method4], "Root(Categ)::-method4")); |
|
return 0; |
} |
/private-1.mm
0,0 → 1,60
/* Test errors for accessing @private and @protected variables. */ |
/* Based on work by: Nicola Pero <nicola@brainstorm.co.uk>. */ |
|
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
@interface MySuperClass |
{ |
@private |
int _private; |
|
@protected |
int _protected; |
|
@public |
int _public; |
} |
- (void) test; |
@end |
|
@implementation MySuperClass |
- (void) test |
{ |
_private = 12; /* Ok */ |
_protected = 12; /* Ok */ |
_public = 12; /* Ok */ |
} |
@end |
|
|
@interface MyClass : MySuperClass |
@end |
|
@implementation MyClass |
- (void) test |
{ |
/* Private variables simply don't exist in the subclass. */ |
_private = 12; /* { dg-error "._private. was not declared in this scope" } */ |
|
_protected = 12; /* Ok */ |
_public = 12; /* Ok */ |
} |
@end |
|
int main (void) |
{ |
MyClass *m = nil; |
|
if (m != nil) |
{ |
int access; |
|
access = m->_private; /* { dg-error "is @private" } */ |
access = m->_protected; /* { dg-error "is @protected" } */ |
access = m->_public; /* Ok */ |
} |
|
return 0; |
} |
/gnu-runtime-2.mm
0,0 → 1,30
/* Sanity check for GNU-runtime version of constant strings, |
regardless of runtime used on target system. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-fgnu-runtime" } */ |
|
#include <objc/Object.h> |
#include <string.h> |
#include <stdlib.h> |
|
@interface NXConstantString: Object |
{ |
char *c_string; |
unsigned int len; |
} |
-(const char *) cString; |
-(unsigned int) length; |
@end |
|
@implementation NXConstantString |
-(const char *) cString { return c_string; } |
-(unsigned int) length { return len; } |
@end |
|
int main(int argc, void **args) |
{ |
if (strcmp ([@"this is a string" cString], "this is a string")) |
abort (); |
return 0; |
} |
/try-catch-10.mm
0,0 → 1,25
/* Check that taking the address of a local variable marked 'volatile' |
by the compiler does not generate untoward errors. */ |
/* Developed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fobjc-exceptions" } */ |
/* { dg-do compile } */ |
|
|
void foo (int *arg1, int *arg2) |
{ |
*arg1 = *arg2; |
} |
|
void bar (int arg) { |
int rcvr; |
|
@try { |
rcvr = arg; |
} |
@finally { |
int *rcvr0 = &rcvr; |
foo (rcvr0, &arg); |
} |
} |
|
/template-4.mm
0,0 → 1,81
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdarg.h> |
#include <stdlib.h> |
|
#ifdef __NEXT_RUNTIME__ |
/* The following ain't pretty, but does allow us to have just one copy |
of next_mapping.h. */ |
#include "../objc/execute/next_mapping.h" |
#else |
#include <objc/NXConstStr.h> |
#endif |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
template <class ARR, class TYPE> class TestT |
{ |
public: |
TYPE k; |
int abc(ARR *array) { |
return [array count] * k; |
} |
TestT(TYPE _k): k(_k) { } |
}; |
|
template <class TYPE> |
const char *getDesc(void) { |
return [TYPE name]; |
} |
|
@class Array; |
|
template <class TYPE> |
int abc(TYPE *xyz, Array *array) { |
return [xyz count] + [array count]; |
} |
|
@interface Array: Object { |
id *arr; |
int count; |
} |
+ (id)arrayWithObjects:(id)first, ... ; |
- (int)count; |
@end |
|
@implementation Array |
+ (id)arrayWithObjects:(id)first, ... { |
Array *a = [Array new]; |
a->count = 0; |
a->arr = (id *) calloc(8, sizeof(id)); |
|
va_list args; |
va_start (args, first); |
|
a->arr[a->count++] = first; |
|
for (id el; el = va_arg(args, id); a->count++) |
a->arr[a->count] = el; |
|
return a; |
} |
- (int)count { |
return count; |
} |
@end |
|
int main(void) { |
CHECK_IF(!strcmp ([@"Object" cString], getDesc<Object>())); |
CHECK_IF(!strcmp ([@"Array" cString], getDesc<Array>())); |
|
Array* a1 = [Array arrayWithObjects:@"One", @"Two", @"Three", nil]; |
Array* a2 = [Array arrayWithObjects:@"Four", @"Five", nil]; |
|
TestT<Array, int> t(7); |
CHECK_IF(t.abc(a1) + t.abc(a2) == 35); |
CHECK_IF(abc(a1, a2) * t.k == 35); |
return 0; |
} |
/comp-types-10.mm
0,0 → 1,19
/* Yet another mysterious gimplifier crasher. */ |
/* { dg-do compile } */ |
/* { dg-options "-O3" } */ |
|
@class NSString; |
@protocol NSObject |
@end |
@interface NSObject <NSObject> { |
} |
@end |
void __setRetained(id *ivar, id value) { |
*ivar = value; |
} |
static NSString *_logProcessPrefix = 0; |
@implementation NSObject (ScopeAdditions) |
+ (void)setObjectLogProcessPrefix:(NSString *)processPrefix { |
__setRetained(&_logProcessPrefix, processPrefix); |
} |
@end |
/bitfield-2.mm
0,0 → 1,78
/* Check if bitfield ivars are inherited correctly (i.e., without |
being "promoted" to ints). */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort(); |
|
@interface Base: Object |
{ |
int full; |
int full2: 32; |
int _refs: 8; |
int field2: 3; |
unsigned f3: 8; |
short cc; |
unsigned g: 16; |
int r2: 8; |
int r3: 8; |
int r4: 2; |
int r5: 8; |
char c; |
} |
- (void)setValues; |
@end |
|
@interface Derived: Base |
{ |
char d; |
int _field3: 6; |
} |
- (void)checkValues; |
@end |
|
@implementation Base |
-(void)setValues { |
full = 1; |
full2 = 2; |
_refs = 3; |
field2 = 1; |
f3 = 6; |
cc = 7; |
g = 8; |
r2 = 9; |
r3 = 10; |
r4 = 1; |
r5 = 12; |
c = 13; |
} |
@end |
|
@implementation Derived |
-(void)checkValues { |
CHECK_IF(full == 1); |
CHECK_IF(full2 == 2); |
CHECK_IF(_refs == 3); |
CHECK_IF(field2 == 1); |
CHECK_IF(f3 == 6); |
CHECK_IF(cc == 7); |
CHECK_IF(g == 8); |
CHECK_IF(r2 == 9); |
CHECK_IF(r3 == 10); |
CHECK_IF(r4 == 1); |
CHECK_IF(r5 == 12); |
CHECK_IF(c == 13); |
} |
@end |
|
int main(void) { |
Derived *obj = [[Derived alloc] init]; |
|
[obj setValues]; |
[obj checkValues]; |
|
return 0; |
} |
/defs.mm
0,0 → 1,43
/* Check @defs() in Objective-C++ */ |
/* Contributed by Devang Patel <dpatel@apple.com> */ |
|
/* { dg-options "-lobjc" } */ |
/* { dg-do run } */ |
|
#include <stdlib.h> |
#include <objc/objc.h> |
#include <objc/Object.h> |
|
extern void abort(void); |
|
@interface A : Object |
{ |
@public |
int a; |
} |
@end |
|
struct A_defs |
{ |
@defs(A); |
}; |
|
@implementation A |
- init |
{ |
a = 42; |
return self; |
} |
@end |
|
|
int main() |
{ |
A *a = [A init]; |
struct A_defs *a_defs = (struct A_defs *)a; |
|
if (a->a != a_defs->a) |
abort (); |
|
return 0; |
} |
/method-5.mm
0,0 → 1,30
/* Do not warn about "slightly" mismatched method signatures if |
-Wstrict-selector-match is off. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-Wno-strict-selector-match" } */ |
|
#include <objc/objc.h> |
|
typedef enum { en1_1, en1_2 } En1; |
typedef enum { en2_1, en2_2 } En2; |
typedef struct { int a, b; } St1; |
typedef struct { unsigned a, b; } St2; |
|
@interface Base |
- (id) meth1: (En1)arg1; |
- (St1) window; |
@end |
|
@interface Derived: Base |
- (id) meth1: (En2)arg1; |
- (St2)window; |
@end |
|
void foo(void) { |
id r; |
En1 en; |
|
[r meth1:en]; |
[r window]; |
} |
/except-1.mm
0,0 → 1,71
/* { dg-do run } */ |
|
/* This tests that exceptions work. It used to fail because |
objc_msgSend was marked with DECL_NOTHROW. |
If you include objc/Object.h, the problem goes away, because |
that file includes objc/objc-runtime.h which explicitly prototypes |
objc_msgSend without 'nothrow'. */ |
|
#include <stdio.h> |
#include <stdlib.h> |
|
|
@interface Object { |
Class isa; |
} |
+ alloc; |
- init; |
@end |
|
// ObjectiveC class header |
@interface ObjCclass : Object { |
} |
-(void)method1; |
-(void)method2; |
@end |
|
// C++ class header |
class CPPclass { |
public: |
void function1(); |
}; |
|
|
// Main |
int main(int argc, char *argv[]) |
{ |
ObjCclass * foo = [[ObjCclass alloc] init]; |
[foo method1]; |
exit (0); |
} |
|
|
// ObjectiveC implementation |
@implementation ObjCclass |
|
-(void) method1 |
{ |
try { |
[self method2]; |
} |
catch(...) { |
return; |
} |
} |
|
-(void) method2 |
{ |
CPPclass foo; |
foo.function1(); |
} |
|
@end |
|
|
// C++ implementation |
void CPPclass::function1() |
{ |
throw (1); |
/* Shouldn't be here because we threw. */ |
abort (); |
} |
/encode-1.mm
0,0 → 1,23
/* Test for graceful encoding of const-qualified fields and parameters. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
|
struct Cxx { |
const struct Cxx *next; |
}; |
|
@interface ObjC { |
const struct Cxx *obj; |
} |
- (ObjC *)initWithCxx: (struct Cxx *const)c and: (const struct Cxx *)d; |
@end |
|
@implementation ObjC |
- (ObjC *)initWithCxx: (struct Cxx *const)c and: (const struct Cxx *)d { |
obj = d; |
return self; |
} |
@end |
|
/* { dg-final { scan-assembler "@\[0-9\]+@0:\[0-9\]+r\\^{Cxx=\\^r{Cxx}}\[0-9\]+\\^r{Cxx}" } } */ |
/super-class-1.mm
0,0 → 1,30
/* Test calling super from within a category method. */ |
|
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
@interface NSObject |
@end |
@interface NSMenuItem: NSObject |
@end |
|
@interface NSObject (Test) |
+ (int) test_func; |
@end |
|
@implementation NSObject (Test) |
+ (int) test_func |
{} |
@end |
|
@interface NSMenuItem (Test) |
+ (int) test_func; |
@end |
|
@implementation NSMenuItem (Test) |
+ (int) test_func |
{ |
return [super test_func]; /* { dg-bogus "invalid use of undefined type" } */ |
} /* { dg-bogus "forward declaration of" "" { target *-*-* } 28 } */ |
@end |
/method-20.mm
0,0 → 1,17
/* Test if context-sensitive "in", "out", "byref", etc., qualifiers can be |
used as method selectors. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do compile } */ |
|
@interface Foo |
- (void)insertNewButtonImage:(Foo *)newButtonImage in:(Foo *)buttonCell; |
+ (oneway void)oneway:(int)i2 byref:(int)i3 out:(float)f4 bycopy:(float)f5; |
@end |
|
@implementation Foo |
- (void)insertNewButtonImage:(Foo *)newButtonImage in:(Foo *)buttonCell { } |
+ (oneway void)oneway:(int)i2 byref:(int)i3 out:(float)f4 bycopy:(float)f5 { } |
@end |
|
/* { dg-final { scan-assembler "insertNewButtonImage:in:" } } */ |
/* { dg-final { scan-assembler "oneway:byref:out:bycopy:" } } */ |
/proto-lossage-5.mm
0,0 → 1,22
/* Do not lose references to forward-declared protocols. */ |
/* { dg-do compile } */ |
@class MyBaseClass; |
@class MyClassThatFails; |
@protocol _MyProtocol; |
|
@interface MyClassThatFails |
- (MyBaseClass<_MyProtocol> *) aMethod; |
@end |
|
@interface MyBaseClass |
@end |
|
@protocol _MyProtocol |
@end |
|
@implementation MyClassThatFails |
- (MyBaseClass<_MyProtocol> *) aMethod |
{ |
return 0; |
} |
@end |
/const-str-7.mm
0,0 → 1,46
/* Test to make sure that the const objc strings are the same across |
scopes. */ |
/* Developed by Andrew Pinski <pinskia@physics.uc.edu> */ |
|
|
/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ |
/* { dg-do run { target *-*-darwin* } } */ |
|
|
#include <stdio.h> |
#include <stdlib.h> |
#include <memory.h> |
#include <objc/objc.h> |
#include <objc/Object.h> |
|
|
@interface Foo: Object { |
char *cString; |
unsigned int len; |
} |
- (char *)customString; |
@end |
|
struct objc_class _FooClassReference; |
|
|
@implementation Foo : Object |
- (char *)customString { |
return cString; |
} |
@end |
|
|
int main () { |
Foo *string = @"bla"; |
{ |
Foo *string2 = @"bla"; |
|
|
if(string != string2) |
abort(); |
printf("Strings are being uniqued properly\n"); |
} |
return 0; |
} |
|
/comp-types-4.mm
0,0 → 1,64
/* 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; |
} |
/try-catch-6.mm
0,0 → 1,14
/* A very simple @try-@catch example. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-fobjc-exceptions" } */ |
|
int foo(void) { |
@try { |
return 2; |
} |
@catch (id foo) { |
return 1; |
} |
return 0; |
} |
/method-14.mm
0,0 → 1,14
/* Check if casting the receiver type causes method lookup to succeed. This was broken |
in Objective-C++. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-do compile } */ |
|
@interface A |
@end |
|
@interface B: A |
- (void)f; |
@end |
|
void g(A *p) { [(B *)p f]; } |
|
/empty-private-1.mm
0,0 → 1,9
/* Test for no entry after @private token. */ |
|
/* { do-do compile } */ |
|
@interface foo |
{ |
@private |
} |
@end |
/ivar-list-semi.mm
0,0 → 1,12
/* Allow for an optional semicolon following the ivar block. */ |
/* Contributed by: Ziemowit Laski <zlaski@apple.com>. */ |
|
#include <objc/Object.h> |
|
@interface Tink : Object { |
@private |
unsigned long mCode[4]; |
}; |
- (id)initWithProc:(void *)inProc; |
- (void *)getUniqueProc; |
@end |
/cxx-scope-2.mm
0,0 → 1,19
/* Make sure Objective-C++ can distinguish ObjC classes from C++ classes. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
#include <iostream> |
#include <string> |
|
@interface iostream: Object |
@end |
|
int main(void) { |
id i = [std::iostream new]; /* { dg-warning "not an Objective\\-C class name or alias" } */ |
i = [iostream new]; |
i = [std::basic_string<char> new]; /* { dg-warning "not an Objective\\-C class name or alias" } */ |
|
return 0; |
} |
/selector-2.mm
0,0 → 1,17
/* Test that we don't ICE when issuing a -Wselector warning. */ |
/* { dg-options "-Wselector" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@interface Foo |
@end |
@implementation Foo |
-(void) foo |
{ |
SEL a; |
a = @selector(b1ar); |
} |
@end |
/* { dg-warning "creating selector for nonexistent method .b1ar." "" { target *-*-* } 0 } */ |
|
/basic.mm
0,0 → 1,21
// A basic sanity check for Objective-C++. |
// { dg-do run } |
|
#include <objc/Object.h> |
#include <iostream> |
|
@interface Greeter : Object |
- (void) greet: (const char *)msg; |
@end |
|
@implementation Greeter |
- (void) greet: (const char *)msg { std::cout << msg; } |
@end |
|
int |
main () |
{ |
std::cout << "Hello from C++\n"; |
Greeter *obj = [Greeter new]; |
[obj greet: "Hello from Objective-C\n"]; |
} |
/stubify-1.mm
0,0 → 1,37
/* All calls must be properly stubified. Complain about any "call |
_objc_msgSend<end-of-line>" without the $stub suffix. */ |
|
/* { dg-do compile { target *-*-darwin* } } */ |
/* { dg-options "-Os -mdynamic-no-pic -fno-exceptions" } */ |
|
typedef struct objc_object { } *id ; |
int x = 41 ; |
|
extern "C" { |
extern id objc_msgSend(id self, char * op, ...); |
extern int bogonic (int, int, int); |
} |
|
@interface Document {} |
- (Document *) window; |
- (Document *) class; |
- (Document *) close; |
@end |
@implementation Document |
- (Document *) class { } |
- (Document *) close { } |
- (Document *) window { } |
- (void)willEndCloseSheet:(void *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { |
[[self window] close]; |
((void (*)(id, char *, int))objc_msgSend)([self class], (char *)contextInfo, 1); |
((void (*)(id, char *, int))bogonic)([self class], (char *)contextInfo, 1); |
bogonic (3, 4, 5); |
x++; |
} |
@end |
|
/* { dg-final { scan-assembler-not "\(bl|call\)\[ \t\]+_objc_msgSend\n" } } */ |
/* { dg-final { scan-assembler "\(bl|call\)\[ \t\]+L_objc_msgSend\\\$stub\n" } } */ |
/* { dg-final { scan-assembler-not "\(bl|call\)\[ \t\]+_bogonic\n" } } */ |
/* { dg-final { scan-assembler "\(bl|call\)\[ \t\]+L_bogonic\\\$stub\n" } } */ |
/* { dg-final { scan-assembler-not "\\\$non_lazy_ptr" } } */ |
/bitfield-5.mm
0,0 → 1,29
|
/* Make sure that bitfield types are printed correctly, and that ivar redeclaration |
(@interface vs. @implementation) checks take the bitfield width into account. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-do compile } */ |
|
@interface Base { |
int i; |
} |
@end |
|
@interface WithBitfields: Base { |
void *isa; |
unsigned a: 3; |
signed b: 4; |
int c: 5; |
} |
@end |
|
@implementation WithBitfields { |
char *isa; /* { dg-error "conflicting instance variable type .char \\*isa." } */ |
/* { dg-error "previous declaration of .void \\*isa." "" { target *-*-* } 13 } */ |
unsigned a: 5; /* { dg-error "conflicting instance variable type .unsigned( int)? a: 5." } */ |
/* { dg-error "previous declaration of .unsigned( int)? a: 3." "" { target *-*-* } 14 } */ |
signed b: 4; /* This one is fine. */ |
int c: 3; /* { dg-error "conflicting instance variable type .int c: 3." } */ |
/* { dg-error "previous declaration of .int c: 5." "" { target *-*-* } 16 } */ |
} |
@end |
/method-8.mm
0,0 → 1,30
/* Tests of duplication. */ |
/* { dg-do compile } */ |
|
@interface class1 |
- (int) meth1; |
- (void) meth1; /* { dg-error "duplicate declaration of method .\\-meth1." } */ |
@end |
|
@interface class2 |
+ (void) meth1; |
+ (int) meth1; /* { dg-error "duplicate declaration of method .\\+meth1." } */ |
@end |
|
@interface class3 |
- (int) meth1; |
@end |
|
@implementation class3 |
- (int) meth1 { return 0; } /* { dg-error "previously defined here" } */ |
- (int) meth1 { return 0; } /* { dg-error "redefinition of" } */ |
@end |
|
@interface class4 |
+ (void) meth1; |
@end |
|
@implementation class4 |
+ (void) meth1 {} /* { dg-error "previously defined here" } */ |
+ (void) meth1 {} /* { dg-error "redefinition of" } */ |
@end |
/isa-field-1.mm
0,0 → 1,43
/* Ensure there are no bizarre difficulties with accessing the 'isa' field of objects. */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@interface Object (Test) |
- (Class) test1: (id)object; |
@end |
|
@interface Derived: Object |
- (Class) test2: (id)object; |
@end |
|
@implementation Object (Test) |
|
Class test1(id object) { |
Class cls = object->isa; |
return cls; |
} |
- (Class) test1: (id)object { |
Class cls = object->isa; |
return cls; |
} |
|
@end |
|
@implementation Derived |
|
Class test2(id object) { |
Class cls = object->isa; |
return cls; |
} |
- (Class) test2: (id)object { |
Class cls = object->isa; |
return cls; |
} |
|
@end |
|
Class test3(id object) { |
Class cls = object->isa; |
return cls; |
} |
/const-str-2.mm
0,0 → 1,7
/* Test the -fconstant-string-class flag error. */ |
/* { dg-do compile } */ |
/* { dg-options "-fconstant-string-class=" } */ |
|
{ dg-error "no class name specified|missing argument" "" { target *-*-* } 0 } |
|
void foo () {} |
/try-catch-1.mm
0,0 → 1,42
/* Test if the compiler accepts @throw / @try..@catch..@finally syntax. */ |
/* Developed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fobjc-exceptions" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
#include <stdio.h> |
#include <setjmp.h> |
|
@interface Frob: Object |
@end |
|
@implementation Frob: Object |
@end |
|
static int exc_control = 0; |
|
int proc() { |
if(exc_control) { |
printf ("Throwing (%d)... ", exc_control); |
@throw [Frob new]; |
} |
return 1; |
} |
|
int foo() |
{ |
@try { |
return proc(); |
} |
@catch (Frob* ex) { |
if(exc_control > 1) { |
printf("Rethrowing (%d)... ", exc_control); |
@throw; |
} |
return 0; |
} |
@finally { |
printf("In @finally block (%d)... ", exc_control); |
} |
} |
/local-decl-1.mm
0,0 → 1,44
/* Test for ivar access inside of class methods. It should be allowed |
(with a warning), but only if no other declarations with the same |
name are seen. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@interface Sprite: Object { |
int sprite, spree; |
} |
+ (void)setFoo:(int)foo; |
+ (void)setSprite:(int)sprite; |
- (void)setFoo:(int)foo; |
- (void)setSprite:(int)sprite; |
@end |
|
int spree = 23; |
|
@implementation Sprite |
+ (void)setFoo:(int)foo { |
sprite = foo; /* { dg-warning "instance variable .sprite. accessed in class method" } */ |
spree = foo; |
} |
+ (void)setSprite:(int)sprite { |
int spree; |
sprite = 15; |
spree = 17; |
((Sprite *)self)->sprite = 16; /* NB: This is how one _should_ access */ |
((Sprite *)self)->spree = 18; /* ivars from within class methods! */ |
} |
- (void)setFoo:(int)foo { |
sprite = foo; |
spree = foo; |
} |
- (void)setSprite:(int)sprite { |
int spree; |
sprite = 15; /* { dg-warning "local declaration of .sprite. hides instance variable" } */ |
self->sprite = 16; |
spree = 17; /* { dg-warning "local declaration of .spree. hides instance variable" } */ |
self->spree = 18; |
} |
@end |
/encode-4.mm
0,0 → 1,104
/* Test Objective-C method encodings. */ |
|
/* The _encoded_ parameter offsets for Objective-C methods are |
computed inductively as follows: |
- The first paramter (self) has offset 0; |
- The k-th parameter (k > 1) has offset equal to the |
sum of: |
- the offset of the k-1-st paramter |
- the (void *)-promoted size of the k-1-st parameter. |
|
Note that the encoded offsets need not correspond |
to the actual placement of parameters (relative to 'self') |
on the stack! Your target's ABI may have very different |
opinions on the matter. */ |
|
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do run } */ |
|
|
#include <objc/objc.h> |
#include <objc/Object.h> |
|
#ifdef __NEXT_RUNTIME__ |
#define METHOD Method |
#define OBJC_GETCLASS objc_getClass |
#define CLASS_GETINSTANCEMETHOD class_getInstanceMethod |
#else |
#include <objc/objc-api.h> |
#define METHOD Method_t |
#define OBJC_GETCLASS objc_get_class |
#define CLASS_GETINSTANCEMETHOD class_get_instance_method |
#endif |
|
#include <stdio.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@interface Foo: Object |
typedef struct { float x, y; } XXPoint; |
typedef struct { float width, height; } XXSize; |
typedef struct _XXRect { XXPoint origin; XXSize size; } XXRect; |
-(id)setRect:(XXRect)r withInt:(int)i; |
-(void) char:(signed char)c float:(float)f double:(double)d long:(long)l; |
@end |
|
XXRect my_rect; |
unsigned offs1, offs2, offs3, offs4, offs5, offs6, offs7; |
|
@implementation Foo |
-(id)setRect:(XXRect)r withInt:(int)i { |
unsigned offs = sizeof(self); |
CHECK_IF(offs == offs3); |
offs += sizeof(_cmd); |
CHECK_IF(offs == offs4); |
offs += sizeof(r); |
CHECK_IF(offs == offs5); |
offs += sizeof(i); |
CHECK_IF(offs == offs1); |
return nil; |
} |
-(void) char:(signed char)c float:(float)f double:(double)d long:(long)l { |
unsigned offs = sizeof(self); |
CHECK_IF(offs == offs3); |
offs += sizeof(_cmd); |
CHECK_IF(offs == offs4); |
offs += sizeof((int)c); |
CHECK_IF(offs == offs5); |
offs += sizeof(f); |
CHECK_IF(offs == offs6); |
offs += sizeof(d); |
CHECK_IF(offs == offs7); |
offs += sizeof(l); |
CHECK_IF(offs == offs1); |
} |
@end |
|
|
int main(void) { |
Foo *foo = [[Foo alloc] init]; |
Class fooClass = OBJC_GETCLASS("Foo"); |
METHOD meth; |
const char *string; |
|
meth = CLASS_GETINSTANCEMETHOD(fooClass, @selector(setRect:withInt:)); |
offs2 = 9999; |
sscanf(meth->method_types, "@%u@%u:%u{_XXRect={?=ff}{?=ff}}%ui%u", &offs1, &offs2, &offs3, |
&offs4, &offs5); |
CHECK_IF(!offs2); |
[foo setRect:my_rect withInt:123]; |
|
meth = CLASS_GETINSTANCEMETHOD(fooClass, @selector(char:float:double:long:)); |
offs2 = 9999; |
if (sizeof (long) == 8) |
string = "v%u@%u:%uc%uf%ud%uq%u"; |
else |
string = "v%u@%u:%uc%uf%ud%ul%u"; |
sscanf(meth->method_types, string, &offs1, &offs2, &offs3, |
&offs4, &offs5, &offs6, &offs7); |
CHECK_IF(!offs2); |
[foo char:'c' float:2.3 double:3.5 long:2345L]; |
|
return 0; |
} |
/try-catch-9.mm
0,0 → 1,65
/* Check that local variables that get modified inside the @try |
block survive until the @catch block is reached. */ |
/* Developed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fobjc-exceptions -O2" } */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
#include <stdio.h> |
|
int gi1 = 9, gi2 = 19; |
float gf1 = 9.0, gf2 = 19.0; |
id obj2 = nil; |
|
void foo (int arg1, float *arg2) |
{ |
int *pi = &gi1; |
float *pf = &gf1; |
id obj1 = nil; |
int local1 = 45, local2 = 47; |
float local3 = 3.0, local4 = 4.0; |
register int local5 = 15; |
static float local6 = 16.0; |
|
@try { |
local1 = 123; |
local2 = 345; |
local3 = 5.0; |
local4 = 6.0; |
local5 = 17; |
local6 = 18.0; |
pi = &gi2; |
pf = &gf2; |
obj2 = obj1 = [Object new]; |
arg1 = 17; |
arg2 = &gf2; |
|
@throw [Object new]; |
} |
@catch (Object *obj) { |
if (local1 != 123 || local2 != 345 || local3 != 5.0 |
|| local4 != 6.0 || local5 != 17 || local6 != 18.0) { |
printf("Abort 1\n"); |
abort(); |
} |
if (pi != &gi2 || pf != &gf2) { |
printf("Abort 2\n"); |
abort(); |
} |
if (!obj1 || obj1 != obj2) { |
printf("Abort 3\n"); |
abort(); |
} |
if (arg1 != 17 || arg2 != &gf2) { |
printf("Abort 4\n"); |
abort(); |
} |
} |
} |
|
int main(void) { |
foo(15, &gf1); |
return 0; |
} |
/comp-types-7.mm
0,0 → 1,38
/* 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 "distinct Objective\\-C type" } */ |
obj_cp2 = obj_p; /* { dg-warning "distinct Objective\\-C 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; |
} |
/method-17.mm
0,0 → 1,33
/* When there is only one candidate method available, make sure the |
compiler uses its argument/return types when constructing the |
message sends (so that proper C/C++ argument conversions may |
take place). */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
static double d = 4.5920234e2; |
|
@interface Foo : Object |
-(void) brokenType: (int)x floatingPoint: (double)y; |
@end |
|
|
@implementation Foo |
-(void) brokenType: (int)x floatingPoint: (double)y |
{ |
CHECK_IF(x == 459); |
CHECK_IF(y == d); |
} |
@end |
|
int main(void) |
{ |
Foo *foo=[Foo new]; |
[foo brokenType: (int)d floatingPoint: d]; |
return 0; |
} |
|
/lookup-1.mm
0,0 → 1,8
/* Simple test to check Objectivec-C++ qualified type lookup. */ |
/* Devang Patel <dpatel@apple.com>. */ |
|
@interface A |
{ |
A *ap; |
} |
@end |
/template-2.mm
0,0 → 1,29
/* Test if ObjC classes (and pointers thereto) can participate |
in C++ overloading. Correct handling of cv-qualifiers is |
key here. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
@interface foo { |
int a, b; |
} |
@end |
|
struct bar { |
int c, d; |
}; |
|
template <class _Tp> |
struct allocator { |
typedef _Tp* pointer; |
typedef const _Tp* const_pointer; |
typedef _Tp& reference; |
typedef const _Tp& const_reference; |
|
pointer address(reference __x) const { return &__x; } |
const_pointer address(const_reference __x) const { return &__x; } |
}; |
|
allocator<bar *> b; |
allocator<foo *> d; |
/no-extra-load.mm
0,0 → 1,24
// Radar 3926484 |
|
// { dg-do compile } |
|
#include <objc/Object.h> |
#include <iostream> |
|
@interface Greeter : Object |
- (void) greet: (const char *)msg; |
@end |
|
@implementation Greeter |
- (void) greet: (const char *)msg { std::cout << msg; } |
@end |
|
int |
main () |
{ |
std::cout << "Hello from C++\n"; |
Greeter *obj = [Greeter new]; |
[obj greet: "Hello from Objective-C\n"]; |
} |
|
/* { dg-final { scan-assembler-not "L_objc_msgSend\\\$non_lazy_ptr" } } */ |
/method-3.mm
0,0 → 1,24
/* Do not warn about "slightly" mismatched method signatures if |
-Wstrict-selector-match is off. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-Wno-strict-selector-match" } */ |
|
#include <objc/objc.h> |
|
@interface Base |
- (id) meth1: (Base *)arg1; |
- (id) window; |
@end |
|
@interface Derived: Base |
- (id) meth1: (Derived *)arg1; |
- (Base *) window; |
@end |
|
void foo(void) { |
id r; |
|
[r meth1:r]; |
[r window]; |
} |
/selector-5.mm
0,0 → 1,13
/* { dg-options "" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
int main() |
{ |
SEL foo = @selector(foo::); |
return 0; |
} |
|
/* { dg-final { scan-assembler "foo::" } } */ |
|
/cxx-ivars-3.mm
0,0 → 1,46
// Check if ObjC classes with non-POD C++ ivars are specially marked in the metadata. |
|
// { dg-do run { target *-*-darwin* } } |
// { dg-options "-fobjc-call-cxx-cdtors -fnext-runtime" } |
|
#include <objc/objc-runtime.h> |
#include <stdlib.h> |
#define CHECK_IF(expr) if(!(expr)) abort() |
|
#ifndef CLS_HAS_CXX_STRUCTORS |
#define CLS_HAS_CXX_STRUCTORS 0x2000L |
#endif |
|
struct cxx_struct { |
int a, b; |
cxx_struct (void) { a = b = 55; } |
}; |
|
@interface Foo { |
int c; |
cxx_struct s; |
} |
@end |
|
@interface Bar: Foo { |
float f; |
} |
@end |
|
@implementation Foo |
@end |
|
@implementation Bar |
@end |
|
int main (void) |
{ |
Class cls; |
|
cls = objc_getClass("Foo"); |
CHECK_IF(cls->info & CLS_HAS_CXX_STRUCTORS); |
cls = objc_getClass("Bar"); |
CHECK_IF(!(cls->info & CLS_HAS_CXX_STRUCTORS)); |
|
return 0; |
} |
/super-dealloc-2.mm
0,0 → 1,46
/* Check for warnings about missing [super dealloc] calls. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
|
@interface Foo { |
void *isa; |
} |
- (void) dealloc; |
- (void) some_other; |
@end |
|
@interface Bar: Foo { |
void *casa; |
} |
- (void) dealloc0; |
@end |
|
@interface Baz: Bar { |
void *usa; |
} |
- (void) dealloc; |
@end |
|
@implementation Foo |
- (void) dealloc { |
isa = 0; /* Should not warn here. */ |
} |
- (void) some_other { |
isa = (void *)-1; |
} |
@end |
|
@implementation Bar |
- (void) dealloc0 { |
casa = 0; |
[super some_other]; /* Should not warn here. */ |
} |
@end |
|
@implementation Baz |
- (void) dealloc { |
usa = 0; |
[super dealloc0]; |
} /* { dg-warning "method possibly missing a .super dealloc. call" } */ |
@end |
/proto-lossage-3.mm
0,0 → 1,25
/* Crash due to descriptionFor(Instance|Class)Method applied to |
a protocol with no instance/class methods respectively. |
Problem report and original fix by richard@brainstorm.co.uk. */ |
/* { dg-do run } */ |
#include <objc/objc.h> |
#include <objc/Object.h> |
#include <objc/Protocol.h> |
|
@protocol NoInstanceMethods |
+ testMethod; |
@end |
|
@protocol NoClassMethods |
- testMethod; |
@end |
|
int |
main() |
{ |
[@protocol(NoInstanceMethods) descriptionForInstanceMethod: @selector(name)]; |
[@protocol(NoInstanceMethods) descriptionForClassMethod: @selector(name)]; |
[@protocol(NoClassMethods) descriptionForInstanceMethod: @selector(name)]; |
[@protocol(NoClassMethods) descriptionForClassMethod: @selector(name)]; |
return 0; |
} |
/const-str-5.mm
0,0 → 1,27
/* Positive test case for constant string layout. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fconstant-string-class=MyConstantString" } */ |
/* { dg-do compile } */ |
|
@interface MyBase { |
const char *p; |
} |
@end |
|
@interface MyConstantString: MyBase { |
union { |
void *u; |
unsigned char *c; |
} _contents; |
unsigned int _count; |
} |
@end |
|
/* The NeXT runtime initializes the 'isa' pointer of string constants at |
compile time. */ |
#ifdef __NEXT_RUNTIME__ |
extern void *_MyConstantStringClassReference; |
#endif |
|
MyConstantString *str = @"Hello"; |
/try-catch-4.mm
0,0 → 1,25
/* Check that the compiler does not incorrectly complain about |
exceptions being caught by previous @catch blocks. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
/* { dg-options "-Wall -fobjc-exceptions" } */ |
|
@interface Exception |
@end |
|
@interface FooException : Exception |
@end |
|
extern void foo(); |
|
void test() |
{ |
@try { |
foo(); |
} |
@catch (FooException* fe) { |
} |
@catch (Exception* e) { |
} |
} |
/comp-types-2.mm
0,0 → 1,88
/* 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 "distinct Objective\\-C type" } */ |
obj_c = obj_cp; /* { dg-warning "distinct Objective\\-C type" } */ |
obj_c = obj_C; /* { dg-warning "distinct Objective\\-C 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" } */ |
obj_p = obj_cp; /* Ok */ |
obj_p = obj_C; /* { dg-warning "distinct Objective\\-C type" } */ |
|
/* Assigning to a 'MyOtherClass *' variable should always generate |
a warning, unless done from an 'id' or an 'id<MyProtocol>' (since |
MyOtherClass implements MyProtocol). */ |
obj_cp = obj; /* Ok */ |
obj_cp = obj_c; /* { dg-warning "distinct Objective\\-C type" } */ |
obj_cp = obj_p; /* Ok */ |
obj_cp = obj_C; /* { dg-warning "distinct Objective\\-C 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 "lacks a cast" } */ |
if (obj_p == obj_c) ; /* { dg-warning "lacks a cast" } */ |
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; |
} |
/method-12.mm
0,0 → 1,31
/* Check that sending messages to variables of type 'Class' does not involve instance methods, unless they reside in root classes. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-options "-Wstrict-selector-match" } */ |
/* { dg-do compile } */ |
|
#include <objc/Protocol.h> |
|
@interface Base |
- (unsigned)port; |
@end |
|
@interface Derived: Base |
- (Object *)port; |
+ (Protocol *)port; |
- (id)starboard; |
@end |
|
void foo(void) { |
Class receiver; |
|
[receiver port]; /* { dg-warning "multiple methods named .\\+port. found" } */ |
/* { dg-warning "using .\\-\\(unsigned( int)?\\)port." "" { target *-*-* } 9 } */ |
/* { dg-warning "also found .\\+\\(Protocol \\*\\)port." "" { target *-*-* } 14 } */ |
|
[receiver starboard]; /* { dg-warning "no .\\+starboard. method found" } */ |
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 25 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 25 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 25 } */ |
|
[Class port]; /* { dg-error ".Class. is not an Objective\\-C class name or alias" } */ |
} |
/encode-7.mm
0,0 → 1,78
/* Check if array arguments of ObjC methods are decayed to pointer types |
in a proper fashion: |
(1) The _encodings_ for the array arguments should remain to be '[4i]' and |
such, since this has been the case since at least gcc 3.3. |
(2) However, when building the static C functions out of ObjC method signatures, |
we need to decay the arrays into pointers (as C does). |
(3) If array size is not known (e.g., 'int a[]'), then the type shall be |
encoded as a pointer. */ |
|
/* Contributed by Alexander Malmberg <alexander@malmberg.org> */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
#include <stdio.h> |
#define CHECK_IF(expr) if(!(expr)) abort() |
|
#ifdef __NEXT_RUNTIME__ |
#define METHOD Method |
#define OBJC_GETCLASS objc_getClass |
#define CLASS_GETINSTANCEMETHOD class_getInstanceMethod |
#else |
#include <objc/objc-api.h> |
#define METHOD Method_t |
#define OBJC_GETCLASS objc_get_class |
#define CLASS_GETINSTANCEMETHOD class_get_instance_method |
#endif |
|
@interface Test : Object |
{ float j; } |
-(void) test2: (int [5])a with: (int [])b; |
-(id) test3: (Test **)b; /* { dg-warning "previous declaration of .\\-\\(id\\)test3:\\(Test \\*\\*\\)b." } */ |
@end |
|
@implementation Test |
-(void) test2: (int [5])a with: (int [])b |
{ |
a[3] = *b; |
} |
-(void) test3: (Test [3][4])b { /* { dg-warning "conflicting types for .\\-\\(void\\)test3:\\(Test \\\[3\\\]\\\[4\\\]\\)b." } */ |
} |
@end |
|
int bb[6] = { 0, 1, 2, 3, 4, 5 }; |
int *b = bb; |
Test *cc[4]; |
Test **c = cc; |
|
int offs1, offs2, offs3, offs4, offs5, offs6; |
|
int main(int argc, char **argv) |
{ |
Class testClass = OBJC_GETCLASS("Test"); |
METHOD meth; |
|
cc[0] = [Test new]; |
CHECK_IF (bb[3] == 3); |
[*c test2: b with: bb + 4]; |
CHECK_IF (bb[3] == 4); |
bb[3] = 0; |
[*c test2: bb with: bb + 5]; |
CHECK_IF (bb[3] == 5); |
|
meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test2:with:)); |
offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1; |
sscanf(meth->method_types, "v%d@%d:%d[%di]%d^i%d", &offs1, &offs2, &offs3, |
&offs4, &offs5, &offs6); |
CHECK_IF (!offs2 && offs4 == 5 && offs3 > 0); |
CHECK_IF (offs5 == 2 * offs3 && offs6 == 3 * offs3 && offs1 == 4 * offs3); |
|
meth = CLASS_GETINSTANCEMETHOD(testClass, @selector(test3:)); |
offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = -1; |
sscanf(meth->method_types, "v%d@%d:%d[%d[%d{Test=#f}]]%d", &offs1, &offs2, &offs3, |
&offs4, &offs5, &offs6); |
CHECK_IF (!offs2 && offs4 == 3 && offs5 == 4 && offs3 > 0); |
CHECK_IF (offs6 == 2 * offs3 && offs1 == 3 * offs3); |
|
return 0; |
} |
/private-2.mm
0,0 → 1,56
/* Test warnings for shadowing instance variables. */ |
/* Based on work by: Nicola Pero <nicola@brainstorm.co.uk>. */ |
|
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
@interface MySuperClass |
{ |
@private |
int _private; |
|
@protected |
int _protected; |
|
@public |
int _public; |
} |
- (void) test; |
@end |
|
@implementation MySuperClass |
- (void) test |
{ |
/* FIXME: I wonder if the warnings shouldn't be better generated |
when the variable is declared, rather than used! */ |
int _private = 12; |
int _protected = 12; |
int _public = 12; |
int a; |
|
a = _private; /* { dg-warning "hides instance variable" } */ |
a = _protected; /* { dg-warning "hides instance variable" } */ |
a = _public; /* { dg-warning "hides instance variable" } */ |
} |
@end |
|
|
@interface MyClass : MySuperClass |
@end |
|
@implementation MyClass |
- (void) test |
{ |
int _private = 12; |
int _protected = 12; |
int _public = 12; |
int a; |
|
/* The private variable can be shadowed without warnings, because |
* it's invisible, and not accessible, to the subclass! */ |
a = _private; /* Ok */ |
a = _protected; /* { dg-warning "hides instance variable" } */ |
a = _public; /* { dg-warning "hides instance variable" } */ |
} |
@end |
/overload-1.mm
0,0 → 1,11
// Make sure we can overload on ObjC classes |
// Radar 3960754 |
|
// { dg-do compile } |
|
@class A, B; |
|
struct X { |
void call(A*); |
void call(B*); |
}; |
/const-str-10.mm
0,0 → 1,28
/* Test if ObjC constant string layout is checked properly, regardless of how |
constant string classes get derived. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-options "-fnext-runtime" } */ |
/* { dg-do compile { target *-*-darwin* } } */ |
|
#include <objc/Object.h> |
|
@interface NSString: Object |
@end |
|
@interface NSSimpleCString : NSString { |
@protected |
char *bytes; |
unsigned int numBytes; |
} |
@end |
|
@interface NSConstantString : NSSimpleCString |
@end |
|
extern struct objc_class _NSConstantStringClassReference; |
|
const NSConstantString *appKey = @"MyApp"; |
|
/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ |
/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */ |
/gnu-runtime-3.mm
0,0 → 1,30
/* Test that compiling for the GNU runtime works (regardless of |
the system runtime used). */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-do run } */ |
/* { dg-options "-fgnu-runtime" } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
@interface FooBar: Object |
- (void)boo; |
@end |
|
int called = 0; |
|
@implementation FooBar |
- (void)boo |
{ |
called ++; |
} |
@end |
|
int main () |
{ |
id fooBarInst = [[FooBar alloc] init]; |
[fooBarInst boo]; |
if (called != 1) |
abort (); |
return 0; |
} |
/try-catch-11.mm
0,0 → 1,40
/* Ensure that @try/@catch blocks do not mess with types of |
local objects (other than their volatile bits). */ |
|
/* { dg-options "-fobjc-exceptions -fnext-runtime" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@protocol Proto1 |
- (int)meth1; |
@end |
|
@protocol Proto2 |
- (int)meth2; |
@end |
|
@interface MyClass: Object <Proto2> { |
int a; |
} |
- (int)meth2; |
- (Object *)parm1: (id)p1 parm2: (id<Proto1>)p2; |
@end |
|
MyClass *mc1, *mc2; |
|
@implementation MyClass |
- (int)meth2 { |
return a; |
} |
- (Object *)parm1: (id)p1 parm2: (id<Proto1>)p2 { |
@try { |
mc2 = p2; /* { dg-warning "type .id <Proto1>. does not conform to the .Proto2. protocol" } */ |
} |
@catch (id exc) { |
return exc; |
} |
mc1 = p1; /* no warning here! */ |
return self; |
} |
@end |
/template-5.mm
0,0 → 1,17
// Test that extern template does not get emitted. |
// Author: Matt Austern <austern@apple.com> |
|
// { dg-do compile } |
// { dg-options "" } |
// { dg-final { scan-assembler-not ".globl __ZN3FooIiE5identEi" } } |
|
template <typename X> |
struct Foo { |
X ident(X x) { return x; } |
}; |
|
extern template struct Foo<int>; |
|
int abcde(Foo<int>& foo, int n) { |
return foo.ident(n); |
} |
/comp-types-11.mm
0,0 → 1,28
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@protocol Foo |
- (id)meth1; |
- (id)meth2:(int)arg; |
@end |
|
@interface Derived1: Object |
@end |
|
@interface Derived2: Object |
+ (Derived1 *)new; |
@end |
|
id<Foo> func(void) { |
Object *o = [Object new]; |
return o; /* { dg-warning "class .Object. does not implement the .Foo. protocol" } */ |
} |
|
@implementation Derived2 |
+ (Derived1 *)new { |
Derived2 *o = [super new]; |
return o; /* { dg-warning "distinct Objective\\-C type in return" } */ |
} |
@end |
|
/bitfield-3.mm
0,0 → 1,55
/* Check if bitfield ivars are correctly @encode'd when |
the NeXT runtime is used. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-fnext-runtime -fsigned-char" } */ |
/* { dg-do run { target *-*-darwin* } } */ |
|
typedef struct objc_object { struct objc_class *class_pointer; } *id; |
|
#include <stdlib.h> |
#include <string.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort(); |
|
@interface Base |
{ |
struct objc_class *isa; |
int full; |
int full2: 32; |
int _refs: 8; |
int field2: 3; |
unsigned f3: 8; |
short cc; |
unsigned g: 16; |
int r2: 8; |
int r3: 8; |
int r4: 2; |
int r5: 8; |
char c; |
} |
@end |
|
@interface Derived: Base |
{ |
char d; |
int _field3: 6; |
} |
@end |
|
@implementation Base |
@end |
|
@implementation Derived |
@end |
|
int main(void) { |
const char *s1r = "{Base=#ib32b8b3b8sb16b8b8b2b8c}"; |
const char *s1 = @encode(Base); |
const char *s2r = "{Derived=#ib32b8b3b8sb16b8b8b2b8ccb6}"; |
const char *s2 = @encode(Derived); |
|
CHECK_IF(!strcmp(s1r, s1)); |
CHECK_IF(!strcmp(s2r, s2)); |
|
return 0; |
} |
/method-6.mm
0,0 → 1,19
/* The following should NOT generate "may not respond to" warnings, |
since a forward-declared @class (instance) should be treated like a |
'Class') ('id'). */ |
|
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@class NotKnown; |
|
void foo(NotKnown *n) { |
[NotKnown new]; |
[n nonexistent_method]; /* { dg-warning "no .\\-nonexistent_method. method found" } */ |
} |
|
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |
|
/encode-2.mm
0,0 → 1,14
/* { dg-do compile } */ |
|
template <class T> |
struct Vec { |
T x, y; |
int z; |
}; |
|
Vec<double> dd; |
const char *enc = @encode(Vec<float>); |
const char *enc2 = @encode(Vec<double>); |
|
/* { dg-final { scan-assembler "{Vec<float>=ffi}" } } */ |
/* { dg-final { scan-assembler "{Vec<double>=ddi}" } } */ |
/super-class-2.mm
0,0 → 1,35
/* Bail out gracefully if attempting to derive from a class that has only been |
forward-declared (via @class). Conversely, @compatibility_alias declarations |
should be traversed to find the @interface. */ |
|
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@class MyWpModule; |
|
@compatibility_alias MyObject Object; |
@compatibility_alias FictitiousModule MyWpModule; |
|
@protocol MySelTarget |
- (id) meth1; |
@end |
|
@protocol Img |
- (id) meth2; |
@end |
|
@interface FunnyModule: FictitiousModule <Img> /* { dg-error ".MyWpModule., superclass of .FunnyModule." } */ |
- (id) meth2; |
@end |
|
@interface MyProjWpModule : MyWpModule <MySelTarget, Img> /* { dg-error ".MyWpModule., superclass of .MyProjWpModule." } */ { |
id i1, i2; |
} |
- (id) meth1; |
- (id) meth2; |
@end |
|
@interface AnotherModule: MyObject <MySelTarget> |
- (id) meth1; |
@end |
/method-21.mm
0,0 → 1,25
/* Test for spurious "may or may not return a value" warnings. */ |
/* { dg-do compile } */ |
/* { dg-options "-Wextra" } */ |
|
#include <objc/Object.h> |
|
@interface Foo: Object |
- (id) meth1; |
- (void) meth2; |
@end |
|
extern int bar; |
|
@implementation Foo |
- (id) meth1 { |
if (bar) |
return [Object new]; |
return; /* { dg-error "return.statement with no value" } */ |
} |
- (void) meth2 { |
if (!bar) |
return; |
bar = 0; |
} |
@end |
/proto-lossage-6.mm
0,0 → 1,17
@class Base; |
@protocol _Protocol; |
|
@interface ClassA { |
} |
-(void) func1:(Base<_Protocol> *)inTarget; |
@end |
|
int main() |
{ |
ClassA* theA = 0; |
Base<_Protocol>* myBase = 0; |
[theA func1:myBase]; |
|
return 0; |
} |
|
/const-str-8.mm
0,0 → 1,39
/* Test for assigning compile-time constant-string objects to static variables. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ |
/* { dg-do run { target *-*-darwin* } } */ |
|
|
#include <stdlib.h> |
#include <objc/Object.h> |
|
@interface Foo: Object { |
char *cString; |
unsigned int len; |
} |
@end |
|
struct objc_class _FooClassReference; |
|
@implementation Foo : Object |
- (char *)customString { |
return cString; |
} |
@end |
|
static const Foo *appKey = @"MyApp"; |
static int CFPreferencesSynchronize (const Foo *ref) { |
return ref == appKey; |
} |
|
static void PrefsSynchronize(void) |
{ |
if(!CFPreferencesSynchronize(appKey)) |
abort(); |
} |
|
int main () { |
PrefsSynchronize(); |
return 0; |
} |
/try-catch-7.mm
0,0 → 1,24
/* { dg-do compile } */ |
/* { dg-options "-fobjc-exceptions" } */ |
|
#include <objc/Object.h> |
|
int main (int argc, const char * argv[]) { |
Object * pool = [Object new]; |
int a; |
|
if ( 1 ) { |
@try { |
a = 1; |
} |
@catch (Object *e) { |
a = 2; |
} |
@finally { |
a = 3; |
} |
} |
|
[pool free]; |
return 0; |
} |
/comp-types-5.mm
0,0 → 1,74
/* Test errors for assignments and comparisons between ObjC and C++ types. */ |
/* Author: Nicola Pero <nicola@brainstorm.co.uk>. */ |
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
/* The NeXT runtime headers do not define NULL. */ |
#ifndef NULL |
#define NULL ((void *)0) |
#endif |
|
@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 = (int *)NULL; |
|
/* These should all generate warnings. */ |
|
obj = i; /* { dg-error "invalid conversion" } */ |
obj = j; /* { dg-error "cannot convert" } */ |
|
obj_p = i; /* { dg-error "invalid conversion" } */ |
obj_p = j; /* { dg-error "cannot convert" } */ |
|
obj_c = i; /* { dg-error "invalid conversion" } */ |
obj_c = j; /* { dg-error "cannot convert" } */ |
|
obj_C = i; /* { dg-error "invalid conversion" } */ |
obj_C = j; /* { dg-error "cannot convert" } */ |
|
i = obj; /* { dg-error "invalid conversion" } */ |
i = obj_p; /* { dg-error "invalid conversion" } */ |
i = obj_c; /* { dg-error "invalid conversion" } */ |
i = obj_C; /* { dg-error "invalid conversion" } */ |
|
j = obj; /* { dg-error "cannot convert" } */ |
j = obj_p; /* { dg-error "cannot convert" } */ |
j = obj_c; /* { dg-error "cannot convert" } */ |
j = obj_C; /* { dg-error "cannot convert" } */ |
|
if (obj == i) ; /* { dg-error "comparison between pointer and integer" } */ |
if (i == obj) ; /* { dg-error "comparison between pointer and integer" } */ |
if (obj == j) ; /* { dg-error "lacks a cast" } */ |
if (j == obj) ; /* { dg-error "lacks a cast" } */ |
|
if (obj_c == i) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (i == obj_c) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (obj_c == j) ; /* { dg-error "lacks a cast" } */ |
if (j == obj_c) ; /* { dg-error "lacks a cast" } */ |
|
if (obj_p == i) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (i == obj_p) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (obj_p == j) ; /* { dg-error "lacks a cast" } */ |
if (j == obj_p) ; /* { dg-error "lacks a cast" } */ |
|
if (obj_C == i) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (i == obj_C) ; /*{ dg-error "comparison between pointer and integer" }*/ |
if (obj_C == j) ; /* { dg-error "lacks a cast" } */ |
if (j == obj_C) ; /* { dg-error "lacks a cast" } */ |
|
return 0; |
} |
/dwarf-2.mm
0,0 → 1,4
/* { dg-options "-gdwarf-2 -dA" } */ |
/* { dg-skip-if "" { { hppa*-*-hpux* *-*-solaris2.[56]* } && { ! hppa*64*-*-* } } { "*" } { "" } } */ |
/* { dg-final { scan-assembler "0x11\[^0-9a-f\].*DW_AT_language" } } */ |
int x; |
/cxx-class-1.mm
0,0 → 1,18
/* Test that Objective-C++ is able to chew through a simple C++ class hierarchy. |
This was broken in earlier ObjC++ incarnations. */ |
|
struct foo |
{ |
foo(void *a) {}; |
}; |
|
struct bar : foo |
{ |
bar() : foo((char*)0) {}; |
}; |
|
class apple : foo |
{ |
public: |
apple() : foo(0) { }; |
}; |
/method-15.mm
0,0 → 1,43
/* Check if finding multiple signatures for a method is handled gracefully when method lookup succeeds (see also method-7.m). */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-options "-Wstrict-selector-match" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@protocol MyObject |
- (id)initWithData:(Object *)data; |
@end |
|
@protocol SomeOther |
- (id)initWithData:(int)data; |
@end |
|
@protocol MyCoding |
- (id)initWithData:(id<MyObject, MyCoding>)data; |
@end |
|
@interface NTGridDataObject: Object <MyCoding> |
{ |
Object<MyCoding> *_data; |
} |
+ (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data; |
@end |
|
@implementation NTGridDataObject |
- (id)initWithData:(id<MyObject, MyCoding>)data { |
return data; |
} |
+ (NTGridDataObject*)dataObject:(id<MyObject, MyCoding>)data |
{ |
NTGridDataObject *result = [[NTGridDataObject alloc] initWithData:data]; |
/* { dg-warning "multiple methods named .\\-initWithData:. found" "" { target *-*-* } 33 } */ |
/* { dg-warning "using .\\-\\(id\\)initWithData:\\(Object \\*\\)data." "" { target *-*-* } 9 } */ |
/* { dg-warning "also found .\\-\\(id\\)initWithData:\\(id <MyObject, MyCoding>\\)data." "" { target *-*-* } 17 } */ |
/* { dg-warning "also found .\\-\\(id\\)initWithData:\\(int\\)data." "" { target *-*-* } 13 } */ |
|
/* The following warning is a consequence of picking the "wrong" method signature. */ |
/* { dg-warning "passing argument 1 of .initWithData:. from distinct Objective\\-C type" "" { target *-*-* } 33 } */ |
return result; |
} |
@end |
/bad-receiver-type.mm
0,0 → 1,15
// { dg-do compile } |
// { dg-options "" } |
|
@interface A |
|
- (void)test; |
|
@end |
|
extern int foo(); |
|
void baz() |
{ |
[foo test]; /* { dg-warning "invalid receiver type" } */ |
} |
/layout-1.mm
0,0 → 1,15
/* Ensure that we do not get bizarre warnings referring to |
__attribute__((packed)) or some such. */ |
/* { dg-do compile } */ |
/* { dg-options "-Wpadded -Wpacked -Wabi" } */ |
|
#include <objc/Object.h> |
|
@interface Derived1: Object |
{ } |
@end |
|
@interface Derived2: Object |
- (id) foo; |
@end |
|
/method-1.mm
0,0 → 1,30
/* Test whether casting 'id' to a specific class removes method lookup |
ambiguity. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
@class Int1, Int2; |
|
@interface Int1 |
+ (Int1 *)classMethod1; |
+ (id)classMethod2; |
- (Int1 *)instanceMethod:(Int2 *)arg; /* { dg-bogus "using" } */ |
@end |
|
@interface Int2: Int1 |
+ (Int1 *)classMethod1; |
+ (id)classMethod2; |
- (id)int2Method; |
- (int)instanceMethod:(int)arg; /* { dg-bogus "also found" } */ |
@end |
|
int main(void) { |
id i = [(Int2 *)[Int1 classMethod1] int2Method]; /* { dg-bogus "may not respond to" } */ |
int j = [(Int2 *)[Int2 classMethod2] instanceMethod: 45]; /* { dg-bogus "multiple methods" } */ |
/* { dg-bogus "invalid conversion" "" { target *-*-* } 25 } */ |
/* { dg-bogus "invalid conversion" "" { target *-*-* } 25 } */ |
return j; |
} |
/extra-semi.mm
0,0 → 1,10
/* Allow extra semicolons in between method declarations, |
for old times' sake. */ |
|
/* { dg-do compile } */ |
|
@interface Foo |
-(Foo *) expiration; |
-(void) setExpiration:(Foo *) date;; |
-(int) getVersion; |
@end |
/selector-3.mm
0,0 → 1,26
/* Test warning for non-existent selectors. */ |
/* This is the "-fgnu-runtime" variant of objc.dg/selector-1.m. */ |
/* { dg-options "-Wselector -fgnu-runtime" } */ |
/* { dg-do compile } */ |
|
typedef struct objc_object { struct objc_class *class_pointer; } *id; |
typedef const struct objc_selector *SEL; |
|
@interface Foo |
- (void) foo; |
- (void) bar; |
@end |
|
@implementation Foo |
- (void) bar |
{ |
} |
|
- (void) foo |
{ |
SEL a,b,c; |
a = @selector(b1ar); |
b = @selector(bar); |
} |
@end /* { dg-warning "creating selector for nonexistent method .b1ar." } */ |
|
/cxx-ivars-1.mm
0,0 → 1,42
// Check if ivars may be accessed via the C++ dot notation. |
|
// { dg-do run } |
// { dg-options "-fno-objc-call-cxx-cdtors" } |
|
#include <objc/Object.h> |
#include <stdlib.h> |
#define CHECK_IF(expr) if(!(expr)) abort() |
|
struct cxx_struct { |
int a, b; |
void set_values (int _a, int _b = 3) { |
a = _a; b = _b; |
} |
~cxx_struct (void) { |
a = b = 99; |
} |
}; |
|
@interface Manip : Object { |
int c; |
cxx_struct s; // { dg-warning "user-defined destructor" } |
// { dg-warning "constructors and destructors will not be invoked" "" { target *-*-* } 22 } |
} |
- (void) manipulate_ivars; |
@end |
|
@implementation Manip |
- (void) manipulate_ivars { |
s.set_values (7); |
CHECK_IF (s.a == 7 && s.b == 3); |
s.~cxx_struct(); |
CHECK_IF (s.a == 99 && s.b == 99); |
} |
@end |
|
int main (void) |
{ |
Manip *obj = [Manip new]; |
[obj manipulate_ivars]; |
[obj free]; |
} |
/extern-c-1.mm
0,0 → 1,18
/* Test extern c support inside @implementation */ |
/* Devang Patel <dpatel@apple.com>. */ |
|
#include <objc/objc.h> |
|
@interface Extern |
@end |
|
@implementation Extern |
|
extern "C" void NSRegisterElement(id element); |
|
- init { |
NSRegisterElement(self); |
return self; |
} |
|
@end |
/stubify-2.mm
0,0 → 1,31
/* All calls must be properly stubified. */ |
/* Testcase extracted from TextEdit:Document.m. */ |
|
/* { dg-do compile { target *-*-darwin* } } */ |
/* { dg-options "-mdynamic-no-pic -fdump-rtl-jump" } */ |
|
typedef struct objc_object { } *id ; |
int x = 41 ; |
extern id objc_msgSend(id self, char * op, ...); |
extern int bogonic (int, int, int) ; |
@interface Document {} |
- (Document *) window; |
- (Document *) class; |
- (Document *) close; |
@end |
@implementation Document |
- (Document *) class { } |
- (Document *) close { } |
- (Document *) window { } |
- (void)willEndCloseSheet:(void *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo { |
[[self window] close]; |
((void (*)(id, char *, int))objc_msgSend)([self class], (char *)contextInfo, 1); |
((void (*)(id, char *, int))bogonic)([self class], (char *)contextInfo, 1); |
bogonic (3, 4, 5); |
x++; |
} |
@end |
|
/* Any symbol_ref of an un-stubified objc_msgSend is an error; look |
for "objc_msgSend" in quotes, without the $stub suffix. */ |
/* { dg-final { scan-file-not stubify-2.mm.08.jump "symbol_ref.*\"objc_msgSend\"" } } */ |
/method-9.mm
0,0 → 1,33
/* Test for lookup of class (factory) methods. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do compile } */ |
|
@interface MyBase |
- (void) rootInstanceMethod; |
@end |
|
@interface MyIntermediate: MyBase |
@end |
|
@interface MyDerived: MyIntermediate |
- (void) instanceMethod; |
+ (void) classMethod; |
@end |
|
@implementation MyDerived |
- (void) instanceMethod { |
} |
|
+ (void) classMethod { /* If a class method is not found, the root */ |
[self rootInstanceMethod]; /* class is searched for an instance method */ |
[MyIntermediate rootInstanceMethod]; /* with the same name. */ |
|
[self instanceMethod]; /* { dg-warning ".MyDerived. may not respond to .\\+instanceMethod." } */ |
[MyDerived instanceMethod]; /* { dg-warning ".MyDerived. may not respond to .\\+instanceMethod." } */ |
} |
@end |
|
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |
|
/proto-error-1.mm
0,0 → 1,4
// PR obj-c++/28434 |
// { dg-do compile } |
|
Class<> c; // { dg-error "identifier" } |
/const-str-3.mm
0,0 → 1,48
/* Test the -fconstant-string-class=Foo option under the NeXT |
runtime. */ |
/* Developed by Markus Hitter <mah@jump-ing.de>. */ |
|
/* { dg-options "-fnext-runtime -fconstant-string-class=Foo -lobjc" } */ |
/* { dg-do run { target *-*-darwin* } } */ |
|
#include <stdio.h> |
#include <stdlib.h> |
#include <memory.h> |
#include <objc/objc.h> |
#include <objc/Object.h> |
|
@interface Foo: Object { |
char *cString; |
unsigned int len; |
} |
- (char *)customString; |
@end |
|
struct objc_class _FooClassReference; |
|
@implementation Foo : Object |
- (char *)customString { |
return cString; |
} |
@end |
|
int main () { |
Foo *string = @"bla"; |
Foo *string2 = @"bla"; |
|
if(string != string2) |
abort(); |
printf("Strings are being uniqued properly\n"); |
|
/* This memcpy has to be done before the first message is sent to a |
constant string object. Can't be moved to +initialize since _that_ |
is already a message. */ |
|
memcpy(&_FooClassReference, objc_getClass("Foo"), sizeof(_FooClassReference)); |
if (strcmp ([string customString], "bla")) { |
abort (); |
} |
|
printf([@"This is a working constant string object\n" customString]); |
return 0; |
} |
/proto-lossage-1.mm
0,0 → 1,44
/* Test for situations in which protocol conformance information |
may be lost, leading to superfluous warnings. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do compile } */ |
|
/* One-line substitute for objc/objc.h */ |
typedef struct objc_object { struct objc_class *class_pointer; } *id; |
|
@protocol NSObject |
- (int)someValue; |
@end |
|
@interface NSObject <NSObject> |
@end |
|
@protocol PlateMethods |
- (void)someMethod; |
@end |
|
@interface Foo { |
NSObject <PlateMethods> *plate; |
id <PlateMethods> plate1; |
NSObject *plate2; |
} |
- (id <PlateMethods>) getPlate; |
- (id <NSObject>) getPlate1; |
- (int) getValue; |
@end |
|
@implementation Foo |
- (id <PlateMethods>) getPlate { |
return plate; /* { dg-bogus "does not implement" } */ |
} |
- (id <NSObject>) getPlate1 { |
return (id <NSObject>)plate1; /* { dg-bogus "does not conform" } */ |
} |
- (int) getValue { |
int i = [plate1 someValue]; /* { dg-warning ".\\-someValue. not found in protocol\\(s\\)" } */ |
|
int j = [(id <NSObject>)plate1 someValue]; /* { dg-bogus "not found in protocol" } */ |
int k = [(id)plate1 someValue]; /* { dg-bogus "not found in protocol" } */ |
return i + j + k; |
} |
@end |
/try-catch-2.mm
0,0 → 1,78
/* Test out '@catch(id foo) {...}', which should catch |
all uncaught exceptions. */ |
/* Developed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fobjc-exceptions" } */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdio.h> |
#include <stdlib.h> |
|
/* The following is not required in actual user code; we include it |
here to check that the compiler generates an internal definition of |
_setjmp that is consistent with what <setjmp.h> provides. */ |
#include <setjmp.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@interface Frob: Object |
@end |
|
@implementation Frob: Object |
@end |
|
static Frob* _connection = nil; |
|
//-------------------------------------------------------------------- |
|
|
void test (Object* sendPort) |
{ |
int cleanupPorts = 1; |
Frob* receivePort = nil; |
|
@try { |
printf ("receivePort = %p\n", receivePort); |
printf ("sendPort = %p\n", sendPort); |
printf ("cleanupPorts = %d\n", cleanupPorts); |
printf ("---\n"); |
|
receivePort = (Frob *) -1; |
_connection = (Frob *) -1; |
printf ("receivePort = %p\n", receivePort); |
printf ("sendPort = %p\n", sendPort); |
printf ("cleanupPorts = %d\n", cleanupPorts); |
printf ("---\n"); |
|
receivePort = nil; |
sendPort = nil; |
cleanupPorts = 0; |
|
printf ("receivePort = %p\n", receivePort); |
printf ("sendPort = %p\n", sendPort); |
printf ("cleanupPorts = %d\n", cleanupPorts); |
printf ("---\n"); |
|
@throw [Object new]; |
} |
@catch(Frob *obj) { |
printf ("Exception caught by incorrect handler!\n"); |
CHECK_IF(0); |
} |
@catch(id exc) { |
printf ("Exception caught by correct handler.\n"); |
printf ("receivePort = %p (expected 0x0)\n", receivePort); |
printf ("sendPort = %p (expected 0x0)\n", sendPort); |
printf ("cleanupPorts = %d (expected 0)\n", cleanupPorts); |
printf ("---"); |
CHECK_IF(!receivePort); |
CHECK_IF(!sendPort); |
CHECK_IF(!cleanupPorts); |
} |
} |
|
int main (void) { |
test((Object *)-1); |
return 0; |
} |
/method-10.mm
0,0 → 1,45
/* Test for sending messages to aliased classes (and instances thereof). */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-lobjc" } */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@interface Int1: Object |
+ (int) classMeth; |
- (int) instanceMeth; |
@end |
|
@interface Int2: Object |
+ (int) classMeth; |
- (int) instanceMeth; |
@end |
|
@implementation Int1 |
+ (int) classMeth { return 345; } |
- (int) instanceMeth { return 697; } |
@end |
|
@implementation Int2 |
+ (int) classMeth { return 1345; } |
- (int) instanceMeth { return 1697; } |
@end |
|
typedef Int1 Int1Typedef; |
@compatibility_alias Int1Alias Int1Typedef; |
@compatibility_alias Int2Alias Int2; |
typedef Int2Alias Int2Typedef; |
|
int main(void) { |
Int1Alias *int1alias = [[Int1Typedef alloc] init]; |
Int2Typedef *int2typedef = [[Int2Alias alloc] init]; |
|
CHECK_IF([Int1Typedef classMeth] == 345 && [Int2Alias classMeth] == 1345); |
CHECK_IF([int1alias instanceMeth] == 697 && [int2typedef instanceMeth] == 1697); |
CHECK_IF([(Int2Typedef *)int1alias instanceMeth] == 697); |
CHECK_IF([(Int1Alias *)int2typedef instanceMeth] == 1697); |
return 0; |
} |
/va-meth-1.mm
0,0 → 1,74
/* Based on objc/execute/va_method.m, by Nicola Pero */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdarg.h> |
#include <stdlib.h> |
|
/* Test methods with "C-style" trailing arguments, with or without ellipsis. */ |
|
@interface MathClass: Object |
/* sum positive numbers; -1 ends the list */ |
+ (int) sum: (int) firstNumber, int secondNumber, ...; |
+ (int) prod: (int) firstNumber, int secondNumber, int thirdNumber; |
+ (int) minimum: (int) firstNumber, ...; |
@end |
|
extern "C" int some_func(id self, SEL _cmd, int firstN, int secondN, int thirdN, ...) { |
return firstN + secondN + thirdN; |
} |
|
@implementation MathClass |
+ (int) sum: (int) firstNumber, int secondNumber, ... |
{ |
va_list ap; |
int sum = 0, number = 0; |
|
va_start (ap, secondNumber); |
number = firstNumber + secondNumber; |
|
while (number >= 0) |
{ |
sum += number; |
number = va_arg (ap, int); |
} |
|
va_end (ap); |
|
return sum; |
} |
+ (int) prod: (int) firstNumber, int secondNumber, int thirdNumber { |
return firstNumber * secondNumber * thirdNumber; |
} |
+ (int) minimum: (int) firstNumber, ... |
{ |
va_list ap; |
int minimum = 999, number = 0; |
|
va_start (ap, firstNumber); |
number = firstNumber; |
|
while (number >= 0) |
{ |
minimum = (minimum < number ? minimum: number); |
number = va_arg (ap, int); |
} |
|
va_end (ap); |
|
return minimum; |
} |
@end |
|
int main (void) |
{ |
if ([MathClass sum: 1, 2, 3, 4, 5, -1] != 15) |
abort (); |
if ([MathClass prod: 4, 5, 6] != 120) |
abort (); |
if ([MathClass minimum: 17, 9, 133, 84, 35, -1] != 9) |
abort (); |
|
return 0; |
} |
/encode-5.mm
0,0 → 1,73
/* Method encoding tests for stand-alone @protocol declarations. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do run } */ |
|
#include <objc/Protocol.h> |
#ifdef __cplusplus |
#define ProtoBool bool |
#else |
#define ProtoBool _Bool |
#endif |
|
#ifndef __NEXT_RUNTIME__ |
#include <objc/objc-api.h> |
#endif |
|
#include <stdio.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
enum Enum { |
zero, one, two, three |
}; |
typedef enum Enum Enum; |
typedef signed char ObjCBool; /* as used by the NeXT runtime */ |
|
@protocol Proto |
union __XXAngle { unsigned int alpha, beta; }; |
typedef struct { float x, y; union __XXAngle a; } XXPoint; |
typedef struct { double width, height; } XXSize; |
typedef struct _XXRect { XXPoint origin; XXSize size; struct _XXRect *next; } XXRect; |
- (void) char:(signed char)c float:(float)f double:(double)d unsigned:(unsigned)u short:(short)s long:(long)l; |
- (void *)setRect:(XXRect)r withBool:(ProtoBool)b withInt:(int)i; |
+ (Enum *)getEnum:(XXPoint *)pt enum:(enum Enum)e bool:(ObjCBool)b; |
+ (ProtoBool **)getBool:(ObjCBool **)b; |
@end |
|
Protocol *proto = @protocol(Proto); |
struct objc_method_description *meth; |
unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7; |
|
static void scan_initial(const char *pattern) { |
totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1; |
sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3, |
&offs4, &offs5, &offs6, &offs7); |
CHECK_IF(!offs0 && offs1 == sizeof(id) && offs2 == offs1 + sizeof(SEL) && totsize >= offs2); |
} |
|
int main(void) { |
const char *string; |
|
meth = [proto descriptionForInstanceMethod: @selector(char:float:double:unsigned:short:long:)]; |
if (sizeof (long) == 8) |
string = "v%u@%u:%uc%uf%ud%uI%us%uq%u"; |
else |
string = "v%u@%u:%uc%uf%ud%uI%us%ul%u"; |
scan_initial(string); |
CHECK_IF(offs3 == offs2 + sizeof(int) && offs4 == offs3 + sizeof(float)); |
CHECK_IF(offs5 == offs4 + sizeof(double) && offs6 == offs5 + sizeof(unsigned)); |
CHECK_IF(offs7 == offs6 + sizeof(int) && totsize == offs7 + sizeof(long)); |
meth = [proto descriptionForInstanceMethod: @selector(setRect:withBool:withInt:)]; |
scan_initial("^v%u@%u:%u{_XXRect={?=ff(__XXAngle=II)}{?=dd}^{_XXRect}}%uB%ui%u"); |
CHECK_IF(offs3 == offs2 + sizeof(XXRect) && offs4 == offs3 + sizeof(int)); |
CHECK_IF(totsize == offs4 + sizeof(int)); |
meth = [proto descriptionForClassMethod: @selector(getEnum:enum:bool:)]; |
scan_initial("^i%u@%u:%u^{?=ff(__XXAngle=II)}%ui%uc%u"); |
CHECK_IF(offs3 == offs2 + sizeof(XXPoint *) && offs4 == offs3 + sizeof(enum Enum)); |
CHECK_IF(totsize == offs4 + sizeof(int)); /* 'ObjCBool' is really 'char' */ |
meth = [proto descriptionForClassMethod: @selector(getBool:)]; |
scan_initial("^^B%u@%u:%u^*%u"); |
CHECK_IF(totsize == offs2 + sizeof(ObjCBool **)); |
return 0; |
} |
/objc-gc-3.mm
0,0 → 1,63
/* Test looking up fields in superclasses in the context of write-barriers |
(where component references get rewritten). */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile { target *-*-darwin* } } */ |
/* { dg-options "-fobjc-gc" } */ |
|
#include <objc/Object.h> |
|
@class MyWindow; |
|
@interface MyDocument : Object { |
MyWindow *_window; |
} |
@end |
|
@interface MyFileDocument : MyDocument { |
struct { |
unsigned int autoClose:1; |
unsigned int openForUI:1; |
unsigned int isClosing:1; |
unsigned int needsDiskCheck:1; |
unsigned int isWritable:1; |
unsigned int representsFileOnDisk:1; |
unsigned int RESERVED:26; |
} _fdFlags; |
} |
@end |
|
@interface MyTextFileDocument : MyFileDocument { |
Object *_textStorage; |
struct __tfdFlags { |
unsigned int immutable:1; |
unsigned int lineEnding:2; |
unsigned int isClosing:1; |
unsigned int settingsAreSet:1; |
unsigned int usesTabs:1; |
unsigned int isUTF8WithBOM:1; |
unsigned int wrapsLines:1; |
unsigned int usingDefaultLanguage:1; |
unsigned int RESERVED:23; |
} _tfdFlags; |
int _tabWidth; |
int _indentWidth; |
} |
@end |
|
@interface MyRTFFileDocument : MyTextFileDocument |
- (BOOL)readFromFile:(const char *)fileName ofType:(const char *)type; |
@end |
|
@implementation MyRTFFileDocument |
- (BOOL)readFromFile:(const char *)fileName ofType:(const char *)type { |
if (_textStorage && fileName) { |
[_textStorage free]; |
return YES; |
} else if (type) { |
_textStorage = [MyRTFFileDocument new]; |
return NO; |
} |
return (fileName && type); |
} |
@end |
/comp-types-8.mm
0,0 → 1,33
/* { dg-do compile } */ |
|
/* We used to ICE because we removed the cast to List_linked* |
in -[ListIndex_linked next]. */ |
|
@interface List |
{ |
@public |
int firstLink; |
} |
@end |
|
@interface ListIndex_linked |
{ |
@public |
List *collection; |
int link; |
} |
@end |
|
@interface List_linked: List |
@end |
|
@implementation List |
@end |
|
@implementation ListIndex_linked |
- next |
{ |
link = ((List_linked*)collection)->firstLink; |
} |
@end |
|
/pragma-1.mm
0,0 → 1,11
/* It is OK to use #pragma inside @interface body. This test checks that. */ |
/* Devang Patel <dpatel@apple.com>. */ |
|
@interface A |
{ |
int p; |
} |
+(int) foo; |
#pragma Mark foobar |
-(int) bar; |
@end |
/method-18.mm
0,0 → 1,25
/* Contributed by Igor Seleznev <selez@mail.ru>. */ |
/* This used to be broken. */ |
|
#include <objc/objc.h> |
|
@interface A |
+ (A *)currentContext; |
@end |
|
@interface B |
+ (B *)currentContext; |
@end |
|
int main() |
{ |
[A currentContext]; /* { dg-bogus "multiple declarations" } */ |
return 0; |
} |
|
@implementation A |
+ (A *)currentContext { return nil; } |
@end |
@implementation B |
+ (B *)currentContext { return nil; } |
@end |
/fix-and-continue-2.mm
0,0 → 1,24
/* Static variables, even if local, require indirect access through a stub |
if -mfix-and-continue is enabled. */ |
|
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do assemble { target *-*-darwin* } } */ |
/* { dg-options "-mfix-and-continue" } */ |
|
#include <objc/Object.h> |
|
@interface Foo: Object |
+ (Object *)indexableFileTypes; |
@end |
|
@implementation Foo |
+ (Object *)indexableFileTypes |
{ |
static Object *fileTypes = 0; |
if(!fileTypes) { |
fileTypes = [Object new]; |
} |
return fileTypes; |
} |
@end |
/lookup-2.mm
0,0 → 1,56
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
class MyWidget { |
public: |
int a; |
MyWidget(void) { a = 17; } |
}; |
|
MyWidget gWidget; |
|
@protocol MyProto |
- (MyWidget *)widget; |
@end |
|
@interface Foo: Object |
@end |
|
@interface Bar: Foo <MyProto> |
@end |
|
@interface Container: Object |
+ (MyWidget *)elementForView:(Foo *)view; |
@end |
|
@implementation Foo |
@end |
|
@implementation Bar |
- (MyWidget *)widget { |
return &gWidget; |
} |
@end |
|
@implementation Container |
+ (MyWidget *)elementForView:(Foo *)view |
{ |
MyWidget *widget = nil; |
if ([view conformsTo:@protocol(MyProto)]) { |
widget = [(Foo <MyProto> *)view widget]; |
} |
return widget; |
} |
@end |
|
int main(void) { |
id view = [Bar new]; |
MyWidget *w = [Container elementForView: view]; |
|
if (!w || w->a != 17) |
abort (); |
|
return 0; |
} |
/gnu-runtime-1.mm
0,0 → 1,19
/* Test that compiling for the GNU runtime works (regardless of |
the system runtime used). */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-do compile } */ |
/* { dg-options "-fgnu-runtime" } */ |
|
#include <objc/Object.h> |
|
@interface FooBar: Object |
- (void)boo; |
@end |
|
int main () |
{ |
id fooBarInst = [[FooBar alloc] init]; |
[fooBarInst boo]; |
return 0; |
} |
|
/template-3.mm
0,0 → 1,80
/* Test for passing arguments to ObjC methods in the context of template |
expansion. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@interface ObjCClass : Object |
{ |
@public |
int info; |
} |
-(id) init; |
-(id) initWithInformation: (int) whatInfo; |
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2; |
@end |
|
void foo(int info) { |
ObjCClass *mObj1 = [[ObjCClass alloc] init]; |
ObjCClass *mObj2 = [[ObjCClass alloc] initWithInformation: info]; |
ObjCClass *mObj3 = [[ObjCClass alloc] initWithInformation: info andInfo: 39]; |
|
CHECK_IF(mObj1->info == 666); |
CHECK_IF(mObj2->info == info); |
CHECK_IF(mObj3->info == info + 39); |
} |
|
template <class WrappedObjCClass> |
class ObjCObjectWrapper |
{ |
public: |
ObjCObjectWrapper(int info); |
WrappedObjCClass *mObj1, *mObj2, *mObj3; |
}; |
|
template <class WrappedObjCClass> |
ObjCObjectWrapper<WrappedObjCClass>::ObjCObjectWrapper(int info) |
{ |
mObj1 = [[WrappedObjCClass alloc] init]; |
mObj2 = [[WrappedObjCClass alloc] initWithInformation: info]; |
mObj3 = [[WrappedObjCClass alloc] initWithInformation: info andInfo: 67]; |
} |
|
@implementation ObjCClass |
-(id) init { |
return [self initWithInformation:666]; |
} |
-(id) initWithInformation: (int) whatInfo { |
[super init]; |
info = whatInfo; |
return self; |
} |
-(id) initWithInformation: (int) whatInfo andInfo: (int) info2 { |
[super init]; |
info = whatInfo + info2; |
return self; |
} |
@end |
|
ObjCObjectWrapper<ObjCClass> staticInstance(42); |
|
int main(void) { |
ObjCObjectWrapper<ObjCClass> stackInstance(47); |
|
foo(89); |
|
CHECK_IF(staticInstance.mObj1->info == 666); |
CHECK_IF(staticInstance.mObj2->info == 42); |
CHECK_IF(staticInstance.mObj3->info == 42 + 67); |
|
CHECK_IF(stackInstance.mObj1->info == 666); |
CHECK_IF(stackInstance.mObj2->info == 47); |
CHECK_IF(stackInstance.mObj3->info == 47 + 67); |
|
return 0; |
} |
/bitfield-1.mm
0,0 → 1,113
/* Check if ObjC class layout follows the ABI (informally) |
set in the past. ObjC structs must be laid out as if |
all ivars, including those inherited from superclasses, |
were defined at once (i.e., any padding introduced for |
superclasses should be removed). */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-Wpadded -Wabi" } */ |
/* { dg-do run } */ |
|
#include <objc/objc.h> |
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
enum Enum { zero, one, two, three, four }; |
|
@interface Base: Object { |
@public |
unsigned a: 2; |
int b: 3; |
enum Enum c: 4; |
unsigned d: 5; |
} /* { dg-warning "padding struct size to alignment boundary" } */ |
@end |
|
struct Base_0 { /* { dg-warning "padding struct size to alignment boundary" } */ |
Class isa; |
unsigned a: 2; |
int b: 3; |
enum Enum c: 4; |
unsigned d: 5; |
}; |
|
@interface Derived: Base { |
@public |
signed e: 5; |
unsigned f: 4; |
enum Enum g: 3; |
} |
@end |
|
struct Derived_0 { |
Class isa; |
unsigned a: 2; |
int b: 3; |
enum Enum c: 4; |
unsigned d: 5; |
signed e: 5; |
int f: 4; |
enum Enum g: 3; |
}; |
|
@interface Leaf: Derived { |
@public |
signed h: 2; |
} |
@end |
|
struct Leaf_0 { |
Class isa; |
unsigned a: 2; |
int b: 3; |
enum Enum c: 4; |
unsigned d: 5; |
signed e: 5; |
unsigned f: 4; |
enum Enum g: 3; |
signed h: 2; |
}; |
|
/* Note that the semicolon after @defs(...) is optional. */ |
|
typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */ |
typedef struct { @defs(Derived); } Derived_t; |
typedef struct { @defs(Leaf); } Leaf_t; |
|
int main(void) |
{ |
struct Leaf_0 l_0; |
Leaf *l = (Leaf *)&l_0; |
Leaf_t *l_t = (Leaf_t *)&l_0; |
|
CHECK_IF(sizeof(Base_t) == sizeof(Base)); |
CHECK_IF(sizeof(Derived_t) == sizeof(Derived)); |
CHECK_IF(sizeof(Leaf_t) == sizeof(Leaf)); |
|
CHECK_IF(sizeof(struct Base_0) == sizeof(Base)); |
CHECK_IF(sizeof(struct Derived_0) == sizeof(Derived)); |
CHECK_IF(sizeof(struct Leaf_0) == sizeof(Leaf)); |
|
l_0.isa = (Class)0; |
l_0.a = 3; |
l_0.b = 0; |
l_0.c = three; |
l_0.d = 31; |
l_0.e = 0; |
l_0.f = 15; |
l_0.g = zero; |
l_0.h = -2; |
|
CHECK_IF(!l_t->isa); |
CHECK_IF(l->a == 3 && l_t->a == 3); |
CHECK_IF(!l->b && !l_t->b); |
CHECK_IF(l->c == three && l_t->c == three); |
CHECK_IF(l->d == 31 && l_t->d == 31); |
CHECK_IF(!l->e && !l_t->e); |
CHECK_IF(l->f == 15 && l_t->f == 15); |
CHECK_IF(l->g == zero && l_t->g == zero); |
CHECK_IF(l->h == -2 && l_t->h == -2); |
|
return 0; |
} |
/method-4.mm
0,0 → 1,24
/* Warn about "slightly" mismatched method signatures if |
-Wstrict-selector-match is on. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-Wstrict-selector-match" } */ |
|
#include <objc/objc.h> |
|
@interface Base |
- (id) meth1: (Base *)arg1; /* { dg-warning "using .\\-\\(id\\)meth1:\\(Base \\*\\)arg1." } */ |
- (id) window; /* { dg-warning "using .\\-\\(id\\)window" } */ |
@end |
|
@interface Derived: Base |
- (id) meth1: (Derived *)arg1; /* { dg-warning "also found .\\-\\(id\\)meth1:\\(Derived \\*\\)arg1." } */ |
- (Base *) window; /* { dg-warning "also found .\\-\\(Base \\*\\)window." } */ |
@end |
|
void foo(void) { |
id r; |
|
[r meth1:r]; /* { dg-warning "multiple methods named .\\-meth1:. found" } */ |
[r window]; /* { dg-warning "multiple methods named .\\-window. found" } */ |
} |
/selector-6.mm
0,0 → 1,13
/* { dg-options "" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
int main() |
{ |
SEL foo = @selector(foo: a::); |
return 0; |
} |
|
/* { dg-final { scan-assembler "foo:a::" } } */ |
|
/const-str-6.mm
0,0 → 1,27
/* Negative test case for constant string layout. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-options "-fconstant-string-class=MyConstantString" } */ |
/* { dg-do compile } */ |
|
@interface MyBase { |
char p; |
} |
@end |
|
@interface MyConstantString: MyBase { |
union { |
void *u; |
unsigned char *c; |
} _contents; |
char _count; |
} |
@end |
|
/* The NeXT runtime initializes the 'isa' pointer of string constants at |
compile time. */ |
#ifdef __NEXT_RUNTIME__ |
extern void *_MyConstantStringClassReference; |
#endif |
|
MyConstantString *str = @"Hello"; /* { dg-error "interface .MyConstantString. does not have valid constant string layout" } */ |
/proto-lossage-4.mm
0,0 → 1,52
/* Test for situations in which protocol conformance information |
may be lost while casting. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-do compile } */ |
|
/* One-line substitute for objc/objc.h */ |
typedef struct objc_object { struct objc_class *class_pointer; } *id; |
|
@protocol Proto |
- (long)someValue; |
@end |
|
@interface Obj |
- (long)anotherValue; |
@end |
|
long foo(void) { |
long receiver = 2; |
Obj *objrcvr; |
Obj <Proto> *objrcvr2; |
|
/* NB: Since 'receiver' is an invalid ObjC message receiver, the compiler |
should warn but then search for methods as if we were messaging 'id'. */ |
|
receiver += [receiver someValue]; /* { dg-warning "invalid receiver type .long int." } */ |
receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .long int." } */ |
|
receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ |
/* { dg-error "invalid conversion" "" { target *-*-* } 28 } */ |
|
receiver += [(Obj *)receiver anotherValue]; |
receiver += [(Obj <Proto> *)receiver someValue]; |
receiver += [(Obj <Proto> *)receiver anotherValue]; |
receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ |
/* { dg-error "invalid conversion" "" { target *-*-* } 34 } */ |
|
receiver += [objrcvr anotherValue]; |
receiver += [(Obj <Proto> *)objrcvr someValue]; |
receiver += [(Obj <Proto> *)objrcvr anotherValue]; |
receiver += [objrcvr2 someValue]; |
receiver += [objrcvr2 anotherValue]; |
receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */ |
/* { dg-warning "invalid conversion" "" { target *-*-* } 42 } */ |
|
receiver += [(Obj *)objrcvr2 anotherValue]; |
|
return receiver; |
} |
|
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |
/comp-types-3.mm
0,0 → 1,38
/* 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; |
} |
/try-catch-5.mm
0,0 → 1,26
/* Check that the compiler does correctly complain about |
exceptions being caught by previous @catch blocks. */ |
/* Force the use of NeXT runtime to see that we don't ICE after |
generating the warning message. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-Wall -fnext-runtime -fobjc-exceptions" } */ |
|
@interface Exception |
@end |
|
@interface FooException : Exception |
@end |
|
extern void foo(); |
|
void test() |
{ |
@try { |
foo(); |
} |
@catch (Exception* e) { /* { dg-warning "earlier handler" } */ |
} |
@catch (FooException* fe) { /* { dg-warning "will be caught" } */ |
} |
} |
/method-13.mm
0,0 → 1,27
/* Check if finding multiple signatures for a method is handled gracefully. Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-options "-Wstrict-selector-match" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@interface Class1 |
- (void)setWindow:(Object *)wdw; |
@end |
|
@interface Class2 |
- (void)setWindow:(Class1 *)window; |
@end |
|
id foo(void) { |
Object *obj = [[Object alloc] init]; |
id obj2 = obj; |
[obj setWindow:nil]; /* { dg-warning ".Object. may not respond to .\\-setWindow:." } */ |
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 18 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 18 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 18 } */ |
[obj2 setWindow:nil]; /* { dg-warning "multiple methods named .\\-setWindow:. found" } */ |
/* { dg-warning "using .\\-\\(void\\)setWindow:\\(Object \\*\\)wdw." "" { target *-*-* } 8 } */ |
/* { dg-warning "also found .\\-\\(void\\)setWindow:\\(Class1 \\*\\)window." "" { target *-*-* } 12 } */ |
|
return obj; |
} |
/proto-qual-1.mm
0,0 → 1,52
/* Check that protocol qualifiers are compiled and encoded properly. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do run } */ |
|
#include <objc/Protocol.h> |
#ifndef __NEXT_RUNTIME__ |
#include <objc/objc-api.h> |
#endif |
#include <stdio.h> |
#include <stdlib.h> |
|
/* The encoded parameter sizes will be rounded up to match pointer alignment. */ |
#define ROUND(s,a) (a * ((s + a - 1) / a)) |
#define aligned_sizeof(T) ROUND(sizeof(T),__alignof(void *)) |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@protocol Retain |
+ (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2; |
- (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2; |
@end |
|
@interface Foo <Retain> |
+ (oneway void)retainArgument:(out bycopy id)arg with:(in signed char **)arg2; |
@end |
|
@implementation Foo |
+ (oneway void)retainArgument:(out bycopy id)arg1 with:(in signed char **)arg2 { } |
- (bycopy) address:(byref inout id)location with:(out short unsigned **)arg2 { return nil; } |
@end |
|
Protocol *proto = @protocol(Retain); |
struct objc_method_description *meth; |
unsigned totsize, offs0, offs1, offs2, offs3, offs4, offs5, offs6, offs7; |
|
static void scan_initial(const char *pattern) { |
totsize = offs0 = offs1 = offs2 = offs3 = offs4 = offs5 = offs6 = offs7 = (unsigned)-1; |
sscanf(meth->types, pattern, &totsize, &offs0, &offs1, &offs2, &offs3, |
&offs4, &offs5, &offs6, &offs7); |
CHECK_IF(!offs0 && offs1 == aligned_sizeof(id) && offs2 == offs1 + aligned_sizeof(SEL) && totsize >= offs2); |
} |
|
int main(void) { |
meth = [proto descriptionForInstanceMethod: @selector(address:with:)]; |
scan_initial("O@%u@%u:%uNR@%uo^^S%u"); |
CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(unsigned)); |
meth = [proto descriptionForClassMethod: @selector(retainArgument:with:)]; |
scan_initial("Vv%u@%u:%uOo@%un^*%u"); |
CHECK_IF(offs3 == offs2 + aligned_sizeof(id) && totsize == offs3 + aligned_sizeof(char **)); |
return 0; |
} |
/encode-8.mm
0,0 → 1,23
/* Test if the Objective-C @encode machinery distinguishes between |
'BOOL *' (which should be encoded as '^c') and 'char *' (which |
should be encoded as '*'). */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-lobjc" } */ |
/* { dg-do run } */ |
|
#include <string.h> |
#include <stdlib.h> |
#include <objc/objc.h> |
|
int main(void) { |
const char *BOOL_ptr = @encode(BOOL *); |
const char *char_ptr = @encode(char *); |
|
if(strcmp(BOOL_ptr, "^c")) |
abort(); |
|
if(strcmp(char_ptr, "*")) |
abort(); |
|
return 0; |
} |
/class-protocol-1.mm
0,0 → 1,442
|
/* Check Class <protocol> types */ |
/* Author: David Ayers <d.ayers@inode.at> */ |
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
#include <objc/objc-api.h> |
|
@protocol MyProto1 |
+(void)doItClass1; |
-(void)doItInstance1; |
@end |
|
@protocol MyProto2 |
+(void)doItClass2; |
-(void)doItInstance2; |
@end |
|
@interface MyClass1 <MyProto1> |
{ |
Class isa; |
} |
@end |
@implementation MyClass1 |
+(void)doItClass1{} |
-(void)doItInstance1{} |
@end |
|
@interface MyClass2 : MyClass1 <MyProto2> |
@end |
@implementation MyClass2 |
+(void)doItClass2{} |
-(void)doItInstance2{} |
@end |
|
@interface MyClass3 |
{ |
Class isa; |
} |
@end |
@interface MyClass4 : MyClass3 <MyProto1> |
@end |
|
/*----------------------------------------*/ |
|
Class cls = 0; |
Class <MyProto1> clsP1 = 0; |
Class <MyProto2> clsP2 = 0; |
|
void |
testSimple(void) |
{ |
[cls doItClass1]; |
[cls doItInstance1]; |
[cls doItClass2]; |
[cls doItInstance2]; |
|
[clsP1 doItClass1]; |
[clsP1 doItInstance1]; /* { dg-warning "instead of" } */ |
[clsP1 doItClass2]; /* { dg-warning "not found in protocol" } */ |
[clsP1 doItInstance2]; /* { dg-warning "not found in protocol" } */ |
|
[clsP2 doItClass1]; /* { dg-warning "not found in protocol" } */ |
[clsP2 doItInstance1]; /* { dg-warning "not found in protocol" } */ |
[clsP2 doItClass2]; |
[clsP2 doItInstance2]; /* { dg-warning "instead of" } */ |
|
[MyClass1 doItClass1]; |
[MyClass1 doItInstance1]; |
[MyClass1 doItClass2]; /* { dg-warning "may not respond to" } */ |
[MyClass1 doItInstance2]; /* { dg-warning "may not respond to" } */ |
|
[MyClass2 doItClass1]; |
[MyClass2 doItInstance1]; |
[MyClass2 doItClass2]; |
[MyClass2 doItInstance2]; /* { dg-warning "may not respond to" } */ |
|
[MyClass3 doItClass1]; /* { dg-warning "may not respond to" } */ |
[MyClass3 doItInstance1]; /* { dg-warning "may not respond to" } */ |
|
[MyClass4 doItClass1]; |
[MyClass4 doItInstance1]; /* { dg-warning "may not respond to" } */ |
} |
|
/*----------------------------------------*/ |
/* Protocols declared by categories */ |
|
@protocol MyProto3 |
+(void)doItClass3; |
-(void)doItInstance3; |
@end |
@protocol MyProto4 |
+(void)doItClass4; |
-(void)doItInstance4; |
@end |
|
@interface MyClass1 (Category1) <MyProto3> |
@end |
@interface MyClass2 (Category2) <MyProto4> |
@end |
|
void |
testCategory(void) |
{ |
[cls doItClass3]; |
[cls doItInstance3]; |
[cls doItClass4]; |
[cls doItInstance4]; |
|
[MyClass1 doItClass3]; |
[MyClass1 doItInstance3]; |
[MyClass1 doItClass4]; /* { dg-warning "may not respond" } */ |
[MyClass1 doItInstance4]; /* { dg-warning "may not respond" } */ |
|
[MyClass2 doItClass3]; |
[MyClass2 doItInstance3]; |
[MyClass2 doItClass4]; |
[MyClass2 doItInstance4]; /* { dg-warning "may not respond" } */ |
|
} |
|
/*----------------------------------------*/ |
/* Inherited protocols declared by categories */ |
|
@protocol MyProto5 <MyProto1> |
+(void)doItClass5; |
-(void)doItInstance5; |
@end |
|
@protocol MyProto6 <MyProto2> |
+(void)doItClass6; |
-(void)doItInstance6; |
@end |
|
@interface MyClass1 (Category3) <MyProto5> |
@end |
@interface MyClass2 (Category4) <MyProto6> |
@end |
|
Class <MyProto5> clsP5 = 0; |
Class <MyProto6> clsP6 = 0; |
|
void |
testCategoryInherited(void) |
{ |
[cls doItClass5]; |
[cls doItInstance5]; |
[cls doItClass6]; |
[cls doItInstance6]; |
|
[clsP5 doItClass1]; |
[clsP5 doItInstance1]; /* { dg-warning "instead of" } */ |
[clsP5 doItClass2]; /* { dg-warning "not found in protocol" } */ |
[clsP5 doItInstance2]; /* { dg-warning "not found in protocol" } */ |
|
[clsP6 doItClass1]; /* { dg-warning "not found in protocol" } */ |
[clsP6 doItInstance1]; /* { dg-warning "not found in protocol" } */ |
[clsP6 doItClass2]; |
[clsP6 doItInstance2]; /* { dg-warning "instead of" } */ |
|
|
[MyClass1 doItClass5]; |
[MyClass1 doItInstance5]; |
[MyClass1 doItClass6]; /* { dg-warning "may not respond" } */ |
[MyClass1 doItInstance6]; /* { dg-warning "may not respond" } */ |
|
[MyClass2 doItClass5]; |
[MyClass2 doItInstance5]; |
[MyClass2 doItClass6]; |
[MyClass2 doItInstance6]; /* { dg-warning "may not respond" } */ |
|
} |
|
/*----------------------------------------*/ |
/* Forward declared root protocols */ |
|
@protocol FwProto; |
|
@interface MyClass1 (Forward) <FwProto> |
@end |
|
Class <FwProto> clsP7 = 0; |
|
void |
testForwardeDeclared1(void) |
{ |
[cls doItClass7]; /* { dg-warning "no .\\+doItClass7. method found" } */ |
[cls doItInstance7]; /* { dg-warning "no .\\+doItInstance7. method found" } */ |
|
[clsP7 doItClass7]; /* { dg-warning "not found in protocol" } */ |
/* { dg-warning "no .\\+doItClass7. method found" "" { target *-*-* } 190 } */ |
[clsP7 doItInstance7]; /* { dg-warning "not found in protocol" } */ |
/* { dg-warning "no .\\+doItInstance7. method found" "" { target *-*-* } 192 } */ |
|
[MyClass1 doItClass7]; /* { dg-warning "may not respond" } */ |
[MyClass1 doItInstance7]; /* { dg-warning "may not respond" } */ |
|
[MyClass2 doItClass7]; /* { dg-warning "may not respond" } */ |
[MyClass2 doItInstance7]; /* { dg-warning "may not respond" } */ |
|
} |
|
@protocol FwProto |
+(void)doItClass7; |
-(void)doItInstance7; |
@end |
|
void |
testForwardeDeclared2(void) |
{ |
[cls doItClass7]; |
[cls doItInstance7]; |
|
[clsP7 doItClass7]; |
[clsP7 doItInstance7]; /* { dg-warning "instead of" } */ |
|
[MyClass1 doItClass7]; |
[MyClass1 doItInstance7]; |
|
[MyClass2 doItClass7]; |
[MyClass2 doItInstance7]; |
} |
|
/*----------------------------------------*/ |
/* Inherited non root protocols */ |
|
@protocol MyProto8 |
+(void)doItClass8; |
-(void)doItInstance8; |
@end |
|
@protocol MyProto9 <MyProto8> |
+(void)doItClass9; |
-(void)doItInstance9; |
@end |
|
@interface MyClass1 (InheritedNonRoot) <MyProto9> |
@end |
|
Class <MyProto8> clsP8 = 0; |
Class <MyProto9> clsP9 = 0; |
|
void |
testInheritedNonRoot(void) |
{ |
[cls doItClass8]; |
[cls doItInstance8]; |
[cls doItClass9]; |
[cls doItInstance9]; |
|
[clsP8 doItClass8]; |
[clsP8 doItInstance8]; /* { dg-warning "instead of" } */ |
[clsP8 doItClass9]; /* { dg-warning "not found in protocol" } */ |
[clsP8 doItInstance9]; /* { dg-warning "not found in protocol" } */ |
|
[clsP9 doItClass8]; |
[clsP9 doItInstance8]; /* { dg-warning "instead of" } */ |
[clsP9 doItClass9]; |
[clsP9 doItInstance9]; /* { dg-warning "instead of" } */ |
|
[MyClass1 doItClass8]; |
[MyClass1 doItInstance8]; |
[MyClass1 doItClass9]; |
[MyClass1 doItInstance9]; |
|
[MyClass2 doItClass8]; |
[MyClass2 doItInstance8]; |
[MyClass2 doItClass9]; |
[MyClass2 doItInstance9]; |
|
} |
|
/*----------------------------------------*/ |
/* Prototype mismatch */ |
|
@protocol MyOtherProto1 |
+(id)doItClass1; |
-(id)doItInstance1; |
@end |
@interface MyOtherClass1 <MyOtherProto1> |
@end |
|
Class <MyOtherProto1> oclsP1; |
|
void |
testPrototypeMismatch(void) |
{ |
id tmp1 = [oclsP1 doItClass1]; |
id tmp2 = [oclsP1 doItInstance1]; /* { dg-warning "instead of" } */ |
|
[clsP1 doItClass1]; |
[clsP1 doItInstance1]; /* { dg-warning "instead of" } */ |
} |
|
id obj = nil; |
id <MyProto1> objP1 = nil; |
id <MyProto2> objP2 = nil; |
id <MyProto5> objP5 = nil; |
int num = 0; |
void *ptr = 0; |
|
MyClass1 *mc1 = nil; |
|
void |
testComptypes(void) |
{ |
{ /* id <protocol>, id <protocol> */ |
objP1 == objP2; /* { dg-warning "lacks a cast" } */ |
objP2 == objP1; /* { dg-warning "lacks a cast" } */ |
|
objP1 == objP5; |
objP5 == objP1; |
} |
{ /* id <protocol>, SomeClass * */ |
mc1 == objP1; |
objP1 == mc1; |
|
mc1 == objP2; /* { dg-warning "lacks a cast" } */ |
objP2 == mc1; /* { dg-warning "lacks a cast" } */ |
} |
{ /* id <protocol>, id */ |
obj == objP1; |
objP1 == obj; |
} |
{ /* id <protocol>, Class */ |
cls == objP1; /* { dg-warning "lacks a cast" } */ |
objP1 == cls; /* { dg-warning "lacks a cast" } */ |
} |
{ /* id <protocol>, non-ObjC */ |
num == objP1; /* { dg-warning "between pointer" } */ |
objP1 == num; /* { dg-warning "between pointer" } */ |
|
ptr == objP1; |
objP1 == ptr; |
} |
{ /* Class <protocol>, Class <protocol> */ |
clsP1 == clsP2; /* { dg-warning "lacks a cast" } */ |
clsP2 == clsP1; /* { dg-warning "lacks a cast" } */ |
|
clsP1 == clsP5; |
clsP5 == clsP1; |
} |
{ /* Class <protocol>, SomeClass * */ |
mc1 == clsP1; /* { dg-warning "lacks a cast" } */ |
clsP1 == mc1; /* { dg-warning "lacks a cast" } */ |
} |
{ /* Class <protocol>, id */ |
obj == clsP1; |
clsP1 == obj; |
} |
{ /* Class <protocol>, Class */ |
cls == clsP1; |
clsP1 == cls; |
} |
{ /* Class <protocol>, non-ObjC */ |
num == clsP1; /* { dg-warning "between pointer" } */ |
clsP1 == num; /* { dg-warning "between pointer" } */ |
|
ptr == clsP1; |
clsP1 == ptr; |
} |
{ /* Class <protocol>, id <protocol> */ |
clsP1 == objP1; /* { dg-warning "lacks a cast" } */ |
objP1 == clsP1; /* { dg-warning "lacks a cast" } */ |
} |
|
{ /* id <protocol>, id <protocol> */ |
objP1 = objP2; /* { dg-warning "does not conform" } */ |
objP2 = objP1; /* { dg-warning "does not conform" } */ |
|
objP1 = objP5; |
objP5 = objP1; /* { dg-warning "does not conform" } */ |
} |
{ /* id <protocol>, SomeClass * */ |
mc1 = objP1; |
objP1 = mc1; |
|
mc1 = objP2; /* { dg-warning "does not conform" } */ |
objP2 = mc1; /* { dg-warning "does not implement" } */ |
} |
{ /* id <protocol>, id */ |
obj = objP1; |
objP1 = obj; |
} |
{ /* id <protocol>, Class */ |
cls = objP1; /* { dg-warning "distinct Objective\\-C type" } */ |
objP1 = cls; /* { dg-warning "distinct Objective\\-C type" } */ |
} |
{ /* id <protocol>, non-ObjC */ |
num = objP1; /* { dg-error "invalid conversion" } */ |
objP1 = num; /* { dg-error "invalid conversion" } */ |
|
ptr = objP1; |
objP1 = ptr; /* { dg-error "invalid conversion" } */ |
} |
{ /* Class <protocol>, Class <protocol> */ |
clsP1 = clsP2; /* { dg-warning "does not conform" } */ |
clsP2 = clsP1; /* { dg-warning "does not conform" } */ |
|
clsP1 = clsP5; |
clsP5 = clsP1; /* { dg-warning "does not conform" } */ |
} |
{ /* Class <protocol>, SomeClass * */ |
/* These combinations should always elicit a warning. */ |
mc1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */ |
clsP1 = mc1; /* { dg-warning "distinct Objective\\-C type" } */ |
|
mc1 = clsP2; /* { dg-warning "distinct Objective\\-C type" } */ |
clsP2 = mc1; /* { dg-warning "distinct Objective\\-C type" } */ |
} |
{ /* Class <protocol>, id */ |
obj = clsP1; |
clsP1 = obj; |
} |
{ /* Class <protocol>, Class */ |
cls = clsP1; |
clsP1 = cls; |
} |
{ /* Class <protocol>, non-ObjC */ |
num = clsP1; /* { dg-error "invalid conversion" } */ |
clsP1 = num; /* { dg-error "invalid conversion" } */ |
|
ptr = clsP1; |
clsP1 = ptr; /* { dg-error "invalid conversion" } */ |
} |
{ /* Class <protocol>, id <protocol> */ |
clsP1 = objP1; /* { dg-warning "distinct Objective\\-C type" } */ |
objP1 = clsP1; /* { dg-warning "distinct Objective\\-C type" } */ |
} |
} |
|
int main () |
{ |
testSimple(); |
testCategory(); |
testCategoryInherited(); |
return(0); |
} |
|
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |
/qual-types-1.mm
0,0 → 1,68
/* Test if ObjC++ can distinguish protocol qualifiers from |
template arguments. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@protocol Zone |
+ allocFromZone:(void *)zone; |
- copyFromZone:(void *)zone; |
@end |
|
@protocol Init <Zone> |
+ initialize; |
- init; |
@end |
|
@interface Foo: Object |
{ @public int val; } |
- init; |
@end |
|
template <class T, class U> struct X { |
T x; U y; |
}; |
|
X<int, float> xx; |
|
template <typename T> struct Holder |
{ |
T *obj; |
static int counter; |
Holder(void) { obj = [[T alloc] init]; } |
~Holder(void) { [obj free]; --counter; } |
id <Init, Zone> getObjId(void) { return obj; } |
Object <Zone, Init> *getObj(void) { return obj; } |
}; |
|
typedef Holder <Foo <Init, Zone> > FooHolder; |
|
@implementation Foo |
-(id) init { |
[super init]; |
val = ++FooHolder::counter; |
return self; |
} |
@end |
|
template <typename T> |
int Holder<T>::counter = 0; |
|
int main (void) { |
CHECK_IF(FooHolder::counter == 0); |
{ |
FooHolder holder; |
CHECK_IF(holder.obj->val == 1); |
CHECK_IF(FooHolder::counter == 1); |
FooHolder holder2; |
CHECK_IF(holder2.obj->val == 2); |
CHECK_IF(FooHolder::counter == 2); |
} |
CHECK_IF(FooHolder::counter == 0); |
return 0; |
} |
/cxx-scope-1.mm
0,0 → 1,53
/* Handle C++ scoping ('::') operators in ObjC message receivers gracefully. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
@class Derived; |
|
Derived *inst[3]; |
|
struct CxxClass { |
static Derived *get_instance(int); |
}; |
|
Derived *CxxClass::get_instance(int offs) { |
return inst[offs]; |
} |
|
@interface Derived: Object { |
int value; |
} |
-(id)initWithValue:(int)val; |
-(int)derived_meth; |
@end |
|
@implementation Derived |
-(id)initWithValue:(int)val { |
[super init]; |
value = val; |
return self; |
} |
- (int)derived_meth { |
return value; |
} |
@end |
|
int main(void) { |
int r; |
inst[1] = [[::Derived alloc] initWithValue:7]; |
inst[2] = [[Derived alloc] initWithValue:77]; |
|
r = [CxxClass::get_instance(2) derived_meth]; |
if (r != 77) |
abort(); |
|
r = [CxxClass::get_instance(1) derived_meth]; |
if (r != 7) |
abort(); |
|
return 0; |
} |
/const-str-11.mm
0,0 → 1,27
/* Test if ObjC constant string layout is checked properly, regardless of how |
constant string classes get derived. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-options "-fnext-runtime -fconstant-string-class=XStr" } */ |
/* { dg-do compile { target *-*-darwin* } } */ |
|
#include <objc/Object.h> |
|
@interface XString: Object { |
@protected |
char *bytes; |
} |
@end |
|
@interface XStr : XString { |
@public |
unsigned int len; |
} |
@end |
|
extern struct objc_class _XStrClassReference; |
|
const XStr *appKey = @"MyApp"; |
|
/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ |
/* { dg-final { scan-assembler ".long\t__XStrClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */ |
/dg.exp
0,0 → 1,37
# GCC Objective-C++ testsuite that uses the `dg.exp' driver. |
# Copyright (C) 2004, 2007 Free Software Foundation, Inc. |
|
# This program is free software; you can redistribute it and/or modify |
# it under the terms of the GNU General Public License as published by |
# the Free Software Foundation; either version 3 of the License, or |
# (at your option) any later version. |
# |
# This program is distributed in the hope that it will be useful, |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
# GNU General Public License for more details. |
# |
# You should have received a copy of the GNU General Public License |
# along with GCC; see the file COPYING3. If not see |
# <http://www.gnu.org/licenses/>. |
|
# Load support procs. |
load_lib obj-c++-dg.exp |
|
# If a testcase doesn't have special options, use these. |
global DEFAULT_OBJCXXFLAGS |
if ![info exists DEFAULT_OBJCXXFLAGS] then { |
set DEFAULT_OBJCXXFLAGS " -ansi -pedantic-errors -Wno-long-long" |
} |
|
# Initialize `dg'. |
dg-init |
|
# Gather a list of all tests. |
set tests [lsort [find $srcdir/$subdir *.mm]] |
|
# Main loop. |
dg-runtest $tests "" $DEFAULT_OBJCXXFLAGS |
|
# All done. |
dg-finish |
/selector-1.mm
0,0 → 1,30
/* Test whether including C++ keywords such as 'and', 'or', |
'not', etc., is allowed inside ObjC selectors (as it must be). */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
@interface Int1 |
+ (int)and_eq:(int)arg1 and:(int)arg2; |
- (int)or_eq:(int)arg1 or:(int)arg3; |
- (int)not:(int)arg1 xor:(int)arg2; |
- (void)bitand:(char)c1 bitor:(char)c2; |
- (void)compl:(float)f1 xor_eq:(double)d1; |
- (void)not_eq; |
@end |
|
@implementation Int1 |
+ (int)and_eq:(int)arg1 and:(int)arg2 { return arg1 + arg2; } |
- (int)or_eq:(int)arg1 or:(int)arg3 { return arg1 + arg3; } |
- (int)not:(int)arg1 xor:(int)arg2 { return arg1 + arg2; } |
- (void)bitand:(char)c1 bitor:(char)c2 { } |
- (void)compl:(float)f1 xor_eq:(double)d1 { } |
- (void)not_eq { } |
@end |
|
/* { dg-final { scan-assembler "\\+\\\[Int1 and_eq:and:\\]|c_Int1__and_eq_and" } } */ |
/* { dg-final { scan-assembler "\\-\\\[Int1 or_eq:or:\\]|i_Int1__or_eq_or" } } */ |
/* { dg-final { scan-assembler "\\-\\\[Int1 not:xor:\\]|i_Int1__not_xor" } } */ |
/* { dg-final { scan-assembler "\\-\\\[Int1 bitand:bitor:\\]|i_Int1__bitand_bitor" } } */ |
/* { dg-final { scan-assembler "\\-\\\[Int1 compl:xor_eq:\\]|i_Int1__compl_xor_eq" } } */ |
/* { dg-final { scan-assembler "\\-\\\[Int1 not_eq\\]|i_Int1__not_eq" } } */ |
/template-6.mm
0,0 → 1,16
// Test that extern template does not get emitted. |
// Author: Matt Austern <austern@apple.com> |
|
// { dg-do compile } |
// { dg-options "" } |
// { dg-final { scan-assembler-not ".globl __ZN3FooIiE5identEi" } } |
|
template <typename X> |
struct Foo { X ident(X x); }; |
|
template <typename X> |
X Foo<X>::ident(X x) { return x; } |
|
extern template struct Foo<int>; |
|
int abcde(Foo<int>& foo, int n) { return foo.ident(n); } |
/comp-types-12.mm
0,0 → 1,14
/* { dg-do compile } */ |
#include <objc/Object.h> |
|
@interface Derived: Object |
@end |
|
extern Object* foo(void); |
static Derived *test(void) |
{ |
Derived *m = foo(); /* { dg-warning "initialization from distinct Objective\\-C type" } */ |
|
return m; |
} |
|
/bitfield-4.mm
0,0 → 1,50
/* Check if the @defs() construct preserves the correct |
layout of bitfields. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-lobjc -Wpadded" } */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
|
#include <stdlib.h> |
#include <string.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
enum Enum { one, two, three, four }; |
|
@interface Base: Object { |
unsigned a: 2; |
int b: 3; |
enum Enum c: 4; |
unsigned d: 5; |
} /* { dg-warning "padding struct size to alignment boundary" } */ |
@end |
|
@interface Derived: Base { |
signed e: 5; |
int f: 4; |
enum Enum g: 3; |
} |
@end |
|
/* Note that the semicolon after @defs(...) is optional. */ |
|
typedef struct { @defs(Base) } Base_t; /* { dg-warning "padding struct size to alignment boundary" } */ |
typedef struct { @defs(Derived); } Derived_t; |
|
int main(void) |
{ |
CHECK_IF(sizeof(Base_t) == sizeof(Base)); |
CHECK_IF(sizeof(Derived_t) == sizeof(Derived)); |
|
#ifdef __NEXT_RUNTIME__ |
CHECK_IF(!strcmp(@encode(Base), "{Base=#b2b3b4b5}")); |
CHECK_IF(!strcmp(@encode(Derived), "{Derived=#b2b3b4b5b5b4b3}")); |
|
CHECK_IF(!strcmp(@encode(Base_t), "{?=#b2b3b4b5}")); |
CHECK_IF(!strcmp(@encode(Derived_t), "{?=#b2b3b4b5b5b4b3}")); |
#endif /* __NEXT_RUNTIME__ */ |
|
return 0; |
} |
/method-7.mm
0,0 → 1,21
/* Check if sending messages to "underspecified" objects is handled gracefully. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
@class UnderSpecified; |
typedef struct NotAClass { |
int a, b; |
} NotAClass; |
|
void foo(UnderSpecified *u, NotAClass *n) { |
[n nonexistent_method]; /* { dg-warning "invalid receiver type" } */ |
/* { dg-warning "no .\\-nonexistent_method. method found" "" { target *-*-* } 12 } */ |
[NotAClass nonexistent_method]; /* { dg-error ".NotAClass. is not an Objective\\-C class name or alias" } */ |
[u nonexistent_method]; /* { dg-warning "no .\\-nonexistent_method. method found" } */ |
[UnderSpecified nonexistent_method]; /* { dg-warning "no .\\+nonexistent_method. method found" } */ |
} |
|
/* { dg-warning "Messages without a matching method signature" "" { target *-*-* } 0 } */ |
/* { dg-warning "will be assumed to return .id. and accept" "" { target *-*-* } 0 } */ |
/* { dg-warning ".\.\.\.. as arguments" "" { target *-*-* } 0 } */ |
/const-str-1.mm
0,0 → 1,25
/* Test errors for constant strings. */ |
/* { dg-do compile } */ |
/* { dg-options "-fgnu-runtime" } */ |
|
#ifdef __cplusplus |
extern void baz(...); |
#endif |
|
void foo() |
{ |
baz(@"hiya"); /* { dg-error "annot find interface declaration" } */ |
} |
|
@interface NXConstantString |
{ |
void *isa; |
char *str; |
int len; |
} |
@end |
|
void bar() |
{ |
baz(@"howdah"); |
} |
/encode-3.mm
0,0 → 1,36
/* { dg-do run } */ |
|
#include <stdlib.h> |
#include <string.h> |
|
template <class T> |
struct Vec { |
T x, y; |
long z; |
long long zz; |
}; |
|
Vec<double> dd; |
const char *enc = @encode(Vec<float>); |
const char *enc2 = @encode(Vec<double>); |
|
#ifdef __LP64__ |
#define L "q" |
#else |
#define L "l" |
#endif |
|
int main(void) { |
const char *encode = @encode(long); |
|
if (strcmp (encode, L)) |
abort(); |
|
if (strcmp (enc, "{Vec<float>=ff" L "q}")) |
abort(); |
|
if (strcmp (enc2, "{Vec<double>=dd" L "q}")) |
abort(); |
|
return 0; |
} |
/const-str-9.mm
0,0 → 1,21
/* Test if ObjC constant strings get placed in the correct section. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-options "-fnext-runtime" } */ |
/* { dg-do compile { target *-*-darwin* } } */ |
/* { dg-skip-if "" { *-*-darwin* } { "-m64" } { "" } } */ |
|
#include <objc/Object.h> |
|
@interface NSConstantString: Object { |
char *cString; |
unsigned int len; |
} |
@end |
|
extern struct objc_class _NSConstantStringClassReference; |
|
const NSConstantString *appKey = @"MyApp"; |
|
/* { dg-final { scan-assembler ".section __OBJC, __cstring_object" } } */ |
/* { dg-final { scan-assembler ".long\t__NSConstantStringClassReference\n\t.long\t.*\n\t.long\t5\n\t.data" } } */ |
/comp-types-6.mm
0,0 → 1,33
/* 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; /* Ok */ |
obj_p = obj_cp; /* Ok */ |
|
if (obj_cp == obj) ; /* Ok */ |
if (obj == obj_cp) ; /* Ok */ |
|
if (obj_cp == obj_p) ; /* Ok */ |
if (obj_p == obj_cp) ; /* Ok */ |
|
return 0; |
} |
/try-catch-8.mm
0,0 → 1,27
/* Test for graceful compilation of @synchronized statements. */ |
|
/* { dg-do compile } */ |
/* { dg-options "-fobjc-exceptions" } */ |
|
#include <objc/Object.h> |
|
@interface Derived: Object |
- (id) meth; |
@end |
|
@implementation Derived |
- (id) meth { |
return self; |
} |
|
static Derived* rewriteDict(void) { |
static Derived *sDict = 0; |
if (sDict == 0) { |
@synchronized ([Derived class]) { |
if (sDict == 0) |
sDict = [Derived new]; |
} |
} |
return sDict; |
} |
@end |
/method-16.mm
0,0 → 1,34
|
/* Ensure that we indeed cannot obtain the value of a message send |
if the chosen method signature returns 'void'. There used to |
exist a cheesy hack that allowed it. While at it, check that |
the first lexically occurring method signature gets picked |
when sending messages to 'id'. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-do compile } */ |
|
#include <objc/objc.h> |
|
@interface Object1 |
- (void)initWithData:(Object1 *)data; |
@end |
|
@interface Object2 |
- (id)initWithData:(Object1 *)data; |
@end |
|
@interface Object3 |
- (id)initWithData:(Object2 *)data; |
@end |
|
void foo(void) { |
id obj1, obj2 = 0; |
obj2 = [obj1 initWithData: obj2]; |
/* { dg-warning "multiple methods named .\\-initWithData:. found" "" { target *-*-* } 26 } */ |
/* { dg-warning "using .\\-\\(void\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } 13 } */ |
/* { dg-warning "also found .\\-\\(id\\)initWithData:\\(Object1 \\*\\)data." "" { target *-*-* } 17 } */ |
/* { dg-warning "also found .\\-\\(id\\)initWithData:\\(Object2 \\*\\)data." "" { target *-*-* } 21 } */ |
|
/* The following error is a consequence of picking the "wrong" method signature. */ |
/* { dg-error "void value not ignored as it ought to be" "" { target *-*-* } 26 } */ |
} |
/template-1.mm
0,0 → 1,49
/* Test for using ObjC classes as C++ template parameters. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#include <stdlib.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@interface Base: Object |
- (int) meth; |
@end |
|
@interface Derived: Base |
- (int) meth; |
@end |
|
static int count = 0; |
|
template <class T> struct Templ |
{ |
T *m; |
int i; |
Templ(): i(55), m([[T alloc] init]) { count++; } |
~Templ() { [m free]; count--; } |
}; |
|
@implementation Base |
- (int) meth { return 333; } |
@end |
|
@implementation Derived |
- (int) meth { return 666; } |
@end |
|
int main (void) { |
CHECK_IF(count == 0); |
{ |
Templ<Derived> derived; |
CHECK_IF(derived.i == 55 && count == 1); |
Templ<Base> base; |
CHECK_IF(base.i == 55 && count == 2); |
CHECK_IF([base.m meth] == 333); |
CHECK_IF([derived.m meth] == 666); |
} |
CHECK_IF(count == 0); |
return 0; |
} |
/method-2.mm
0,0 → 1,56
/* Test if prior method lookup at method @implementation time is not |
overly aggressive, leading to methods being found in other classes. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
|
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@class NSString; |
|
@protocol NSMenuItem |
+ (void)setUsesUserKeyEquivalents:(BOOL)flag; |
+ (BOOL)usesUserKeyEquivalents; |
@end |
|
@interface NSMenuItem : Object <NSMenuItem> { |
@private |
id _menu; |
} |
@end |
|
@interface NSResponder : Object <NSMenuItem> |
{ |
id _nextResponder; |
} |
@end |
|
@interface Object(NSMenuValidation) |
- (BOOL)validateMenuItem:(id <NSMenuItem>)menuItem; |
@end |
|
@interface NSResponder (NSStandardKeyBindingMethods) |
- (void)insertText:(id)insertString; |
- (void)doCommandBySelector:(SEL)aSelector; |
@end |
|
@interface NSView : NSResponder |
{ |
id _superview; |
id _subviews; |
} |
@end |
|
@interface SKTGraphicView : NSView { |
@private |
float _gridSpacing; |
} |
@end |
|
@implementation SKTGraphicView |
- (BOOL)validateMenuItem:(NSMenuItem *)item { |
return (BOOL)1; |
} |
- (void)insertText:(NSString *)str { |
} |
@end |
/selector-4.mm
0,0 → 1,26
/* Test warning for non existing selectors. */ |
/* Contributed by Devang Patel <dpatel@apple.com>. */ |
|
/* { dg-options "-Wselector -fnext-runtime" } */ |
/* { dg-do compile } */ |
|
typedef struct objc_object { struct objc_class *class_pointer; } *id; |
typedef struct objc_selector *SEL; |
|
@interface Foo |
- (void) foo; |
- (void) bar; |
@end |
|
@implementation Foo |
- (void) bar |
{ |
} |
|
- (void) foo |
{ |
SEL a,b,c; |
a = @selector(b1ar); /* { dg-warning "creating selector for nonexistent method .b1ar." } */ |
b = @selector(bar); |
} |
@end |
/cxx-ivars-2.mm
0,0 → 1,76
// Check if the '- .cxx_construct' and '-.cxx_destruct' methods get called |
// and if they perform their desired function. |
|
// { dg-do run } |
// { dg-options "-fobjc-call-cxx-cdtors" } |
|
#include <objc/Object.h> |
#include <stdlib.h> |
#define CHECK_IF(expr) if(!(expr)) abort() |
|
static int ctor1_called, ctor2_called, dtor1_called; |
|
struct bar { |
int a, b; |
bar(void) { |
a = 5; b = 6; |
ctor1_called++; |
} |
~bar(void) { |
a = b = 99; |
dtor1_called++; |
} |
}; |
|
struct boo: bar { |
int c; |
boo(int _c = 9): c(_c) { |
ctor2_called++; |
} |
}; |
|
@interface Baz: Object { |
@public |
bar aa; |
} |
@end |
|
@implementation Baz |
@end |
|
@interface Foo: Baz { |
@public |
int a; |
boo bb; |
bar b; |
float c; |
bar d; |
} |
@end |
|
@implementation Foo |
@end |
|
int main (void) |
{ |
CHECK_IF(!ctor1_called && !ctor2_called && !dtor1_called); /* are we sane? */ |
|
Baz *baz = [Baz new]; |
CHECK_IF(ctor1_called && !ctor2_called && !dtor1_called); |
CHECK_IF(baz->aa.a == 5 && baz->aa.b == 6); |
ctor1_called = 0; /* reset */ |
|
[baz free]; |
CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called); |
dtor1_called = 0; /* reset */ |
|
Foo *foo = [Foo new]; |
CHECK_IF(ctor1_called && ctor2_called && !dtor1_called); |
CHECK_IF(foo->bb.a == 5 && foo->bb.b == 6 && foo->bb.c == 9); |
CHECK_IF(foo->b.a == 5 && foo->b.b == 6); |
CHECK_IF(foo->d.a == 5 && foo->d.b == 6); |
ctor1_called = ctor2_called = 0; /* reset */ |
|
[foo free]; |
CHECK_IF(!ctor1_called && !ctor2_called && dtor1_called); |
} |
/typedef-alias-1.mm
0,0 → 1,16
/* Typedefs of ObjC types should work without any bogus warnings. */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
typedef Object MyObject; |
|
int main (int argc, const char * argv[]) |
{ |
Object* a = nil; |
MyObject* b = a; |
Object* c = b; |
|
return 0; |
} |
|
/const-str-4.mm
0,0 → 1,31
/* Ensure that the preprocessor handles ObjC string constants gracefully. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
/* { dg-options "-fnext-runtime -fconstant-string-class=MyString -lobjc" } */ |
/* { dg-do run { target *-*-darwin* } } */ |
|
#include <stdlib.h> |
|
@interface MyString |
{ |
void *isa; |
char *str; |
int len; |
} |
@end |
|
#define kMyStringMacro1 "My String" |
#define kMyStringMacro2 @"My String" |
|
void *_MyStringClassReference; |
|
@implementation MyString |
@end |
|
int main(void) { |
MyString* aString1 = @kMyStringMacro1; |
MyString* aString2 = kMyStringMacro2; |
if(aString1 != aString2) { |
abort(); |
} |
return 0; |
} |
/proto-lossage-2.mm
0,0 → 1,20
/* Don't forget to look in protocols if a class (and its superclasses) do not |
provide a suitable method. */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
@protocol Zot |
-(void) zot; |
@end |
|
@interface Foo : Object <Zot> |
@end |
|
int foo() |
{ |
Foo *f=nil; |
[f zot]; /* There should be no warnings here! */ |
return 0; |
} |
|
/super-dealloc-1.mm
0,0 → 1,46
/* Check for warnings about missing [super dealloc] calls. */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
|
@interface Foo { |
void *isa; |
} |
- (void) dealloc; |
- (void) some_other; |
@end |
|
@interface Bar: Foo { |
void *casa; |
} |
- (void) dealloc; |
@end |
|
@interface Baz: Bar { |
void *usa; |
} |
- (void) dealloc; |
@end |
|
@implementation Foo |
- (void) dealloc { |
isa = 0; /* Should not warn here. */ |
} |
- (void) some_other { |
isa = (void *)-1; |
} |
@end |
|
@implementation Bar |
- (void) dealloc { |
casa = 0; |
[super some_other]; |
} /* { dg-warning "method possibly missing a .super dealloc. call" } */ |
@end |
|
@implementation Baz |
- (void) dealloc { |
usa = 0; |
[super dealloc]; /* Should not warn here. */ |
} |
@end |
/comp-types-1.mm
0,0 → 1,16
/* { dg-do compile } */ |
|
@interface A |
+ new; |
@end |
|
@interface B : A |
@end |
|
int main(int argc, char **argv) { |
B *b = [B new]; |
A *a = b; |
|
return (b == a); |
} |
|
/try-catch-3.mm
0,0 → 1,18
/* Test if caught exception objects are accessible inside the |
@catch block. (Yes, I managed to break this.) */ |
/* Author: Ziemowit Laski <zlaski@apple.com> */ |
|
/* { dg-do compile } */ |
/* { dg-options "-fobjc-exceptions" } */ |
|
#include <objc/Object.h> |
|
const char *foo(void) |
{ |
@try { |
return "foo"; |
} |
@catch (Object* theException) { |
return [theException name]; |
} |
} |
/method-11.mm
0,0 → 1,25
/* Check if class references (generated for the NeXT runtime) are appropriately |
folded. This test is safe to run on all targets. */ |
/* Author: Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-fnext-runtime" } */ |
/* { dg-do compile } */ |
|
#include <objc/Object.h> |
|
typedef Object ObjectTypedef1; |
typedef ObjectTypedef1 ObjectTypedef2; |
@compatibility_alias ObjectAlias1 ObjectTypedef2; |
@compatibility_alias ObjectAlias2 ObjectAlias1; |
typedef ObjectAlias2 ObjectTypedef3; |
|
void foo(void) { |
id obj = [Object new]; |
obj = [ObjectTypedef1 new]; |
obj = [ObjectTypedef2 new]; |
obj = [ObjectTypedef3 new]; |
obj = [ObjectAlias1 new]; |
obj = [ObjectAlias2 new]; |
} |
|
/* { dg-final { scan-assembler "_OBJC_CLASS_REFERENCES_0" } } */ |
/* { dg-final { scan-assembler-not "_OBJC_CLASS_REFERENCES_1" } } */ |
/encode-6.mm
0,0 → 1,74
/* Encoding tests for ObjC class layouts. */ |
/* Contributed by Ziemowit Laski <zlaski@apple.com>. */ |
/* { dg-options "-lobjc" } */ |
/* { dg-do run } */ |
|
#include <objc/Object.h> |
#ifdef __NEXT_RUNTIME__ |
#include <objc/objc-class.h> |
#define OBJC_GETCLASS objc_getClass |
#else |
#include <objc/objc-api.h> |
#define OBJC_GETCLASS objc_get_class |
#endif |
|
#include <stdlib.h> |
#include <string.h> |
|
#define CHECK_IF(expr) if(!(expr)) abort() |
|
@class Int1, Int2; |
struct Nested; |
|
struct Innermost { |
unsigned char a, b; |
struct Nested *encl; |
}; |
|
struct Nested { |
float a, b; |
Int1 *next; |
struct Innermost innermost; |
}; |
|
@interface Int1: Object { |
signed char a, b; |
Int2 *int2; |
struct Nested nested; |
} |
@end |
|
@interface Int2: Int1 { |
struct Innermost *innermost; |
Int1 *base; |
} |
@end |
|
@implementation Int1 |
@end |
|
@implementation Int2 |
@end |
|
struct objc_ivar *ivar; |
|
static void check_ivar(const char *name, const char *type) { |
CHECK_IF(!strcmp(ivar->ivar_name, name)); |
CHECK_IF(!strcmp(ivar->ivar_type, type)); |
ivar++; |
} |
|
int main(void) { |
ivar = ((Class)OBJC_GETCLASS("Int1"))->ivars->ivar_list; |
check_ivar("a", "c"); |
check_ivar("b", "c"); |
check_ivar("int2", "@\"Int2\""); |
check_ivar("nested", |
"{Nested=\"a\"f\"b\"f\"next\"@\"Int1\"\"innermost\"{Innermost=\"a\"C\"b\"C\"encl\"^{Nested}}}"); |
|
ivar = ((Class)OBJC_GETCLASS("Int2"))->ivars->ivar_list; |
check_ivar("innermost", "^{Innermost=CC^{Nested}}"); |
check_ivar("base", "@\"Int1\""); |
|
return 0; |
} |
/pragma-2.mm
0,0 → 1,23
/* It is OK to use #pragma inside @implementation body. This test checks that. */ |
/* Ziemowit Laski <zlaski@apple.com>. */ |
|
@interface A |
{ |
int p; |
} |
+(int) foo; |
-(int) bar; |
@end |
|
@implementation A |
#pragma mark - |
#pragma mark init / dealloc |
+ (int)foo { |
return 1; |
} |
#pragma mark - |
#pragma mark Private Functions |
- (int)bar { |
return 2; |
} |
@end |
/comp-types-9.mm
0,0 → 1,25
/* { dg-do compile } */ |
|
/* Another gimplifier ICE... */ |
|
#include <objc/Object.h> |
|
@interface MyView: Object { |
int _frame; |
} |
- (void)_finalize; |
@end |
|
@interface MyViewTemplate: MyView { |
void *_className; |
} |
- (id)createRealObject; |
@end |
|
@implementation MyViewTemplate |
- (id)createRealObject { |
id realObj; |
*(MyView *)realObj = *(MyView *)self; |
return realObj; |
} |
@end |