| 1 |
// { dg-do run } |
| 2 |
template <typename _Tp, long _Nm> struct A { |
| 3 |
typedef _Tp _Type[_Nm]; |
| 4 |
static _Tp &_S_ref(const _Type &p1, int p2) { |
| 5 |
return const_cast<_Tp &>(p1[p2]); |
| 6 |
} |
| 7 |
}; |
| 8 |
template <typename _Tp, long _Nm> struct B { |
| 9 |
typedef A<_Tp, _Nm> _AT_Type; |
| 10 |
typename _AT_Type::_Type _M_elems; |
| 11 |
_Tp &operator[](long p1) const { return _AT_Type::_S_ref(_M_elems, p1); } |
| 12 |
}; |
| 13 |
int t; |
| 14 |
void foo(int p1, int &p2) { |
| 15 |
if ((t & 1) == 0) { |
| 16 |
if (p1 != 1) |
| 17 |
__builtin_abort(); |
| 18 |
if (p2 != 2) |
| 19 |
__builtin_abort(); |
| 20 |
} |
| 21 |
t++; |
| 22 |
} |
| 23 |
__attribute__((noinline)) |
| 24 |
void test1(const B<int, 2> &p1) { foo(p1[0], p1[1]); } |
| 25 |
void test(B<B<int, 2>, 2> &p1) { |
| 26 |
test1(p1[0]); |
| 27 |
test1(p1[1]); |
| 28 |
foo(p1[0][0], p1[0][1]); |
| 29 |
} |
| 30 |
int main() { |
| 31 |
B<B<int, 2>, 2> t; |
| 32 |
t[0][0] = 1; |
| 33 |
t[0][1] = 2; |
| 34 |
test(t); |
| 35 |
} |