| 1 |
// PR c++/69836 |
| 2 |
// { dg-do compile { target c++11 } } |
| 3 |
|
| 4 |
template<int N = 25> struct number : public number<N - 1> { |
| 5 |
static constexpr int value = N; |
| 6 |
static constexpr number<N-1> prev() { return {}; } |
| 7 |
}; |
| 8 |
template<> struct number<0> { static constexpr int value = 0; }; |
| 9 |
|
| 10 |
template<int N> struct S { enum { value = N }; }; |
| 11 |
|
| 12 |
template<int X> constexpr S<X+1> increment(S<X>) { return {}; } |
| 13 |
|
| 14 |
#define RETURN(R) -> decltype(R) { return R; } |
| 15 |
|
| 16 |
#define INIT(TYPE) \ |
| 17 |
using W_ThisType = TYPE; \ |
| 18 |
friend constexpr S<0> state(number<0>, W_ThisType**) { return {}; } |
| 19 |
|
| 20 |
#define STUFF \ |
| 21 |
friend constexpr auto state(number<decltype(state(number<>{}, static_cast<W_ThisType**>(nullptr)))::value+1> w_counter, \ |
| 22 |
W_ThisType **w_this) \ |
| 23 |
RETURN(increment(state(w_counter.prev(), w_this))) |
| 24 |
|
| 25 |
|
| 26 |
template <typename T> struct TemplateObject { |
| 27 |
INIT(TemplateObject) |
| 28 |
STUFF |
| 29 |
STUFF |
| 30 |
}; |
| 31 |
|
| 32 |
int main() { |
| 33 |
TemplateObject<int> t; |
| 34 |
constexpr auto s = state(number<>{}, static_cast<TemplateObject<int>**>(nullptr)) ; |
| 35 |
static_assert(s.value == 2, ""); |
| 36 |
} |