| 1 |
// PR c++/79937 |
| 2 |
// This is a constexpr adaptation of pr79937-3.C and pr79937-4.C. |
| 3 |
// { dg-do compile { target c++14 } } |
| 4 |
|
| 5 |
struct X { |
| 6 |
unsigned i; |
| 7 |
unsigned n = i; |
| 8 |
}; |
| 9 |
|
| 10 |
constexpr X bar(X x) { |
| 11 |
return x; |
| 12 |
} |
| 13 |
|
| 14 |
struct Y |
| 15 |
{ |
| 16 |
static constexpr Y bar(Y y) { return y; } |
| 17 |
unsigned i; |
| 18 |
unsigned n = bar(Y{2,i}).n; |
| 19 |
}; |
| 20 |
|
| 21 |
constexpr X x { 1, bar(X{2}).n }; |
| 22 |
static_assert(x.n == 2, ""); |
| 23 |
|
| 24 |
constexpr Y y { 1 }; |
| 25 |
static_assert(y.n == 1, ""); |
| 26 |
|
| 27 |
struct Z { |
| 28 |
unsigned i; |
| 29 |
unsigned n = i; |
| 30 |
unsigned m = i; |
| 31 |
}; |
| 32 |
|
| 33 |
constexpr Z |
| 34 |
baz (Z z) |
| 35 |
{ |
| 36 |
if (z.i != 1 || z.n != 2 || z.m != 1) |
| 37 |
__builtin_abort (); |
| 38 |
return z; |
| 39 |
} |
| 40 |
|
| 41 |
constexpr Z z = baz (Z {1, Z {2}.n}); |
| 42 |
static_assert(z.i == 1 && z.n == 2 && z.m == 1, ""); |