1 // { dg-do run } 2 // GROUPS passed temps 3 // temps file 4 // Message-Id: <9212181914.AA05066@sparc1.cnm.us.es> 5 // From: juando@cnm.us.es (Juan Domingo Martin Gomez) 6 // Subject: Temporaries destroyed too soon 7 // Date: Fri, 18 Dec 92 20:14:45 +0100 8 9 #include <stdio.h> 10 11 int status = 0; 12 int fail = 0; 13 14 class Foo 15 { 16 public: 17 Foo(); 18 ~Foo(); 19 20 Foo &method(); 21 }; 22 f1()23Foo f1() 24 { 25 return Foo(); 26 } 27 Foo()28Foo::Foo() 29 { 30 } 31 ~Foo()32Foo::~Foo() 33 { 34 if (status == 2) 35 fail = 0; 36 else 37 fail = 1; 38 } 39 method()40Foo &Foo::method() 41 { 42 status++; 43 return *this; 44 } 45 main()46int main() 47 { 48 // f1() returns a temporary object. The member function 49 // method() returns a reference to the same object. 50 f1().method().method(); 51 if (fail) 52 { printf ("FAIL\n"); return 1; } 53 else 54 printf ("PASS\n"); 55 } 56