| 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 |
| 12 |
|
| 13 |
extern "C" int printf (const char *, ...); |
| 14 |
|
| 15 |
struct base { |
| 16 |
mutable int data_member; |
| 17 |
|
| 18 |
base () {} |
| 19 |
void function_member () const; |
| 20 |
}; |
| 21 |
|
| 22 |
base base_object; |
| 23 |
|
| 24 |
base base_returning_function (); |
| 25 |
|
| 26 |
int call_count = 0; |
| 27 |
|
| 28 |
int main () |
| 29 |
{ |
| 30 |
const base& base_ref = base_returning_function (); |
| 31 |
|
| 32 |
base_ref.function_member (); |
| 33 |
base_ref.function_member (); |
| 34 |
base_ref.data_member = 99; |
| 35 |
|
| 36 |
if (call_count == 1) |
| 37 |
printf ("PASS\n"); |
| 38 |
else |
| 39 |
{ printf ("FAIL\n"); return 1; } |
| 40 |
|
| 41 |
return 0; |
| 42 |
} |
| 43 |
|
| 44 |
base base_returning_function () |
| 45 |
{ |
| 46 |
base local_base_object; |
| 47 |
|
| 48 |
call_count++; |
| 49 |
return local_base_object; |
| 50 |
} |
| 51 |
|
| 52 |
void base::function_member () const |
| 53 |
{ |
| 54 |
} |