| 1 |
// PR c++/100209 |
| 2 |
// { dg-do compile { target c++14 } } |
| 3 |
|
| 4 |
template<typename Derived> |
| 5 |
struct __a_t |
| 6 |
{ |
| 7 |
unsigned char A = 0; |
| 8 |
constexpr Derived & SetA(const unsigned char & value) { |
| 9 |
A = value; |
| 10 |
return *static_cast<Derived *>(this); |
| 11 |
} |
| 12 |
}; |
| 13 |
|
| 14 |
template<typename Derived> |
| 15 |
struct __b_t |
| 16 |
{ |
| 17 |
unsigned char B = 0; |
| 18 |
constexpr Derived & SetB(const unsigned char & value) { |
| 19 |
B = value; |
| 20 |
return *static_cast<Derived *>(this); |
| 21 |
} |
| 22 |
}; |
| 23 |
|
| 24 |
struct __ab_t : __a_t<__ab_t>, __b_t<__ab_t> { }; |
| 25 |
|
| 26 |
constexpr auto AB = __ab_t().SetA(100).SetB(10); |
| 27 |
static_assert(AB.A == 100, ""); |
| 28 |
static_assert(AB.B == 10, ""); |