OSDN Git Service

2005-02-03 Andrew Pinski <pinskia@physics.uc.edu>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.dg / lookup / java1.C
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
6 extern "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
21 typedef struct java::lang::Object* jobject;
22 typedef struct java::lang::Throwable* jthrowable;
23 typedef class java::lang::Class* jclass;
24 using java::lang::Foo;
25
26 class Foo : public java::lang::Throwable
27 {
28 public:
29   static ::java::lang::Class class$;
30 };
31
32
33 /*
34  * Step 1: no declarations. A declaration for _Jv_Throw is created.
35  */
36
37 void 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
48 extern "C" jobject _Jv_AllocObject (jclass) __attribute__((__malloc__));
49
50 void Bar2(void)
51 {
52   Foo* f = new java::lang::Foo; 
53   throw (f);  
54 }
55
56
57 /*
58  * Step 3: overloads
59  */
60
61 jobject _Jv_AllocObject (jclass, jint, float) __attribute__((__malloc__));
62 void _Jv_Throw (int, float) __attribute__ ((__noreturn__));
63
64 void 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 }