| 1 |
// PR c++/19199 |
| 2 |
|
| 3 |
// { dg-do run } |
| 4 |
|
| 5 |
// We used to turn the COND_EXPR lvalue into a MIN_EXPR rvalue, and |
| 6 |
// then return a reference to a temporary in qMin. |
| 7 |
|
| 8 |
#include <assert.h> |
| 9 |
|
| 10 |
enum Foo { A, B }; |
| 11 |
|
| 12 |
template<typename T> T &qMin(T &a, T &b) |
| 13 |
{ |
| 14 |
return a < b ? a : b; |
| 15 |
} |
| 16 |
|
| 17 |
int main (int, char **) |
| 18 |
{ |
| 19 |
Foo f = A; |
| 20 |
Foo g = B; |
| 21 |
Foo &h = qMin(f, g); |
| 22 |
assert (&h == &f || &h == &g); |
| 23 |
const Foo &i = qMin((const Foo&)f, (const Foo&)g); |
| 24 |
assert (&i == &f || &i == &g); |
| 25 |
return 0; |
| 26 |
} |
| 27 |
|