Debian Codegraph @

gcc/testsuite/g++.old-deja/g++.law/temps2.C

raw
1 // { dg-do run }
2 // GROUPS passed temps
3 // temps file
4 // Message-Id: <[email protected]>
5 // From: [email protected] (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
23 Foo f1()
24 {
25 return Foo();
26 }
27
28 Foo::Foo()
29 {
30 }
31
32 Foo::~Foo()
33 {
34 if (status == 2)
35 fail = 0;
36 else
37 fail = 1;
38 }
39
40 Foo &Foo::method()
41 {
42 status++;
43 return *this;
44 }
45
46 int 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 }