java1.C revision 1.1.1.1
1// { dg-do compile } 2// { dg-options "-fdollars-in-identifiers" } 3// Origin: Giovanni Bajo <giovannibajo at libero dot it> 4// Make sure that Java special functions can be called correctly. 5 6extern "Java" 7{ 8 typedef __java_int jint; 9 namespace java 10 { 11 namespace lang 12 { 13 class Class; 14 class Object; 15 class Throwable {}; 16 class Foo; 17 } 18 } 19} 20 21typedef struct java::lang::Object* jobject; 22typedef struct java::lang::Throwable* jthrowable; 23typedef class java::lang::Class* jclass; 24using java::lang::Foo; 25 26class Foo : public java::lang::Throwable 27{ 28public: 29 static ::java::lang::Class class$; 30}; 31 32 33/* 34 * Step 1: no declarations. A declaration for _Jv_Throw is created. 35 */ 36 37void Bar1(void) 38{ 39 Foo* f = new java::lang::Foo; // { dg-error "call to Java constructor" } 40 throw (f); 41} 42 43 44/* 45 * Step 2: constructor declaration 46 */ 47 48extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__)); 49 50void Bar2(void) 51{ 52 Foo* f = new java::lang::Foo; 53 throw (f); 54} 55 56 57/* 58 * Step 3: overloads 59 */ 60 61jobject _Jv_AllocObject (jclass, jint, float) __attribute__((__malloc__)); 62void _Jv_Throw (int, float) __attribute__ ((__noreturn__)); 63 64void Bar3(void) 65{ 66 Foo* f = new java::lang::Foo; // { dg-error "should never be overloaded" } 67 throw (f); // { dg-error "should never be overloaded" } 68} 69