fix pr/45972
[official-gcc.git] / gcc / testsuite / obj-c++.dg / const-str-3.mm
blob5ea8e229fbef84b0b04ba82a8e94fc0cef3d3482
1 /* Test the -fconstant-string-class=Foo option under the NeXT
2    runtime.  */
3 /* Developed by Markus Hitter <mah@jump-ing.de>.  */
5 /* { dg-options "-fconstant-string-class=Foo" } */
6 /* { dg-do run { target *-*-darwin* } } */
7 /* { dg-xfail-run-if "Needs OBJC2 ABI" { *-*-darwin* && { lp64 && { ! objc2 } } } { "-fnext-runtime" } { "" } } */
9 #import "../objc-obj-c++-shared/Object1.h"
10 #import "../objc-obj-c++-shared/next-mapping.h"
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <memory.h>
14 #include <objc/objc.h>
15 #ifndef __NEXT_RUNTIME__
16 #include <objc/objc-api.h>
17 #endif
19 @interface Foo: Object {
20   char *cString;
21   unsigned int len;
23 - (char *)customString;
24 @end
26 #ifdef NEXT_OBJC_USE_NEW_INTERFACE
27 struct fudge_objc_class _FooClassReference;
28 #else
29 struct objc_class _FooClassReference;
30 #endif
32 @implementation Foo : Object
33 - (char *)customString {
34   return cString;
36 @end
38 int main () {
39   Foo *string = @"bla";
40   Foo *string2 = @"bla";
42   if(string != string2)
43     abort();
44   printf("Strings are being uniqued properly\n");
46   /* This memcpy has to be done before the first message is sent to a
47      constant string object. Can't be moved to +initialize since _that_
48      is already a message. */
50   memcpy(&_FooClassReference, objc_get_class("Foo"), sizeof(_FooClassReference));
51   if (strcmp ([string customString], "bla")) {
52     abort ();
53   }
55   printf([@"This is a working constant string object\n" customString]);
56   return 0;
58 #include "../objc-obj-c++-shared/Object1-implementation.h"