summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.old-deja/g++.brendan/reference1.C
blob: 92ff38d7dfda4e427d0e155f52f8ce7bc88fc35d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// { dg-do run  }
// { dg-options "-w" }
// GROUPS passed references
// Check that if a reference is initialized to refer to a value
// which is returned from a function call, the actual call to
// the function is only invoked for the original initialization
// of the reference, and not for each subsequent use of the
// reference.
//
// This test fails with G++ 1.35.0- (pre-release).
// Reported 4/4/89 by Kim Smith

extern "C" int printf (const char *, ...); 

struct base {
	mutable int data_member;

	base () {}
	void function_member () const;
};

base base_object;

base base_returning_function ();

int call_count = 0;

int main ()
{
	const base& base_ref = base_returning_function ();

	base_ref.function_member ();
	base_ref.function_member ();
	base_ref.data_member  = 99;

	if (call_count == 1)
	  printf ("PASS\n");
	else
	  { printf ("FAIL\n"); return 1; }

	return 0;
}

base base_returning_function ()
{
	base local_base_object;

	call_count++;
	return local_base_object;
}

void base::function_member () const
{
}