| 1 |
// PR c++/26714 |
| 2 |
// { dg-do run } |
| 3 |
|
| 4 |
extern "C" void abort(); |
| 5 |
|
| 6 |
bool ok = false; |
| 7 |
struct A { |
| 8 |
A() { } |
| 9 |
~A() { if (!ok) abort(); } |
| 10 |
}; |
| 11 |
|
| 12 |
struct B { |
| 13 |
static A foo() { return A(); } |
| 14 |
}; |
| 15 |
|
| 16 |
B b_g; |
| 17 |
|
| 18 |
struct scoped_ptr { |
| 19 |
B* operator->() const { return &b_g; } |
| 20 |
B* get() const { return &b_g; } |
| 21 |
}; |
| 22 |
|
| 23 |
B *get() { return &b_g; } |
| 24 |
|
| 25 |
int main() |
| 26 |
{ |
| 27 |
scoped_ptr f; |
| 28 |
const A& ref1 = f->foo(); |
| 29 |
const A& ref2 = f.get()->foo(); |
| 30 |
const A& ref3 = get()->foo(); |
| 31 |
const A& ref4 = B::foo(); |
| 32 |
B *pf = f.get(); |
| 33 |
const A& ref5 = pf->foo(); |
| 34 |
|
| 35 |
|
| 36 |
ok = true; |
| 37 |
} |