| 1 |
// PR c++/98675 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
struct S { |
| 5 |
int x = 0; |
| 6 |
constexpr const int& get() const { return x; } |
| 7 |
}; |
| 8 |
|
| 9 |
constexpr int error() { |
| 10 |
const auto& local = S{}.get(); // { dg-message "note: declared here" } |
| 11 |
return local; // { dg-error "accessing '\[^'\]+' outside its lifetime" } |
| 12 |
} |
| 13 |
constexpr int x = error(); // { dg-message "in .constexpr. expansion" } |
| 14 |
|
| 15 |
constexpr int ok() { |
| 16 |
// temporary should only be destroyed after end of full-expression |
| 17 |
auto local = S{}.get(); |
| 18 |
return local; |
| 19 |
} |
| 20 |
constexpr int y = ok(); |