aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/g++.dg/init/lifetime3.C
blob: d099699f86827979b3a285a84f0c738a71ad2f41 (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
// PR c++/26714
// { dg-do run }

extern "C" void abort();

bool ok = false;
struct A {
  A() { }
  ~A() { if (!ok) abort(); }
};

struct B {
  static A foo() { return A(); }
};

B b_g;

struct scoped_ptr {
  B* operator->() const { return &b_g; }
  B* get() const { return &b_g; }
};

B *get() { return &b_g; }

int main()
{
  scoped_ptr f;
  const A& ref1 = f->foo();
  const A& ref2 = f.get()->foo();
  const A& ref3 = get()->foo();
  const A& ref4 = B::foo();
  B *pf = f.get();
  const A& ref5 = pf->foo();


  ok = true;
}