| 1 |
// PR c++/66477 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
struct a { constexpr bool g() const { return true; } }; |
| 5 |
constexpr bool g(a&) { return true;} |
| 6 |
constexpr bool h(a) { return true;} |
| 7 |
|
| 8 |
a a1; |
| 9 |
a& ar = a1; |
| 10 |
|
| 11 |
void f(a ap, a& arp) |
| 12 |
{ |
| 13 |
a a2; |
| 14 |
a& ar2 = a2; |
| 15 |
|
| 16 |
// Most of these are OK because no data is actually loaded. |
| 17 |
static_assert (a1.g(),""); |
| 18 |
static_assert (g(a1),""); |
| 19 |
static_assert (h(a1),""); |
| 20 |
|
| 21 |
static_assert (a2.g(),""); |
| 22 |
static_assert (g(a2),""); |
| 23 |
static_assert (h(a2),""); |
| 24 |
|
| 25 |
static_assert (ap.g(),""); |
| 26 |
static_assert (g(ap),""); |
| 27 |
static_assert (h(ap),""); |
| 28 |
|
| 29 |
static_assert (ar.g(),""); |
| 30 |
static_assert (g(ar),""); |
| 31 |
static_assert (h(ar),""); |
| 32 |
|
| 33 |
// But these are specifically prohibited in [expr.const]/4.12: |
| 34 |
// * an id-expression that refers to a variable or data member of reference |
| 35 |
// type unless the reference has a preceding initialization and either |
| 36 |
// ** it is usable in constant expressions or |
| 37 |
// ** its lifetime began within the evaluation of e; |
| 38 |
|
| 39 |
static_assert (ar2.g(),""); // { dg-error "constant" } |
| 40 |
static_assert (g(ar2),""); // { dg-error "constant" } |
| 41 |
static_assert (h(ar2),""); // { dg-error "constant" } |
| 42 |
|
| 43 |
static_assert (arp.g(),""); |
| 44 |
static_assert (g(arp),""); |
| 45 |
static_assert (h(arp),""); // { dg-error "constant" } |
| 46 |
} |