2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / testsuite / g++.old-deja / g++.brendan / reference1.C
blob92ff38d7dfda4e427d0e155f52f8ce7bc88fc35d
1 // { dg-do run  }
2 // { dg-options "-w" }
3 // GROUPS passed references
4 // Check that if a reference is initialized to refer to a value
5 // which is returned from a function call, the actual call to
6 // the function is only invoked for the original initialization
7 // of the reference, and not for each subsequent use of the
8 // reference.
9 //
10 // This test fails with G++ 1.35.0- (pre-release).
11 // Reported 4/4/89 by Kim Smith
13 extern "C" int printf (const char *, ...); 
15 struct base {
16         mutable int data_member;
18         base () {}
19         void function_member () const;
22 base base_object;
24 base base_returning_function ();
26 int call_count = 0;
28 int main ()
30         const base& base_ref = base_returning_function ();
32         base_ref.function_member ();
33         base_ref.function_member ();
34         base_ref.data_member  = 99;
36         if (call_count == 1)
37           printf ("PASS\n");
38         else
39           { printf ("FAIL\n"); return 1; }
41         return 0;
44 base base_returning_function ()
46         base local_base_object;
48         call_count++;
49         return local_base_object;
52 void base::function_member () const