1 // Special g++ Options: -w 2 // GROUPS passed references 3 // Check that if a reference is initialized to refer to a value 4 // which is returned from a function call, the actual call to 5 // the function is only invoked for the original initialization 6 // of the reference, and not for each subsequent use of the 7 // reference. 8 // 9 // This test fails with G++ 1.35.0- (pre-release). 10 // Reported 4/4/89 by Kim Smith 11 12 extern "C" int printf (const char *, ...); 13 14 struct base { 15 mutable int data_member; 16 basebase17 base () {} 18 void function_member () const; 19 }; 20 21 base base_object; 22 23 base base_returning_function (); 24 25 int call_count = 0; 26 main()27int main () 28 { 29 const base& base_ref = base_returning_function (); 30 31 base_ref.function_member (); 32 base_ref.function_member (); 33 base_ref.data_member = 99; 34 35 if (call_count == 1) 36 printf ("PASS\n"); 37 else 38 { printf ("FAIL\n"); return 1; } 39 40 return 0; 41 } 42 base_returning_function()43base base_returning_function () 44 { 45 base local_base_object; 46 47 call_count++; 48 return local_base_object; 49 } 50 function_member()51void base::function_member () const 52 { 53 } 54