| 1 |
// { dg-do run { target c++14 } } |
| 2 |
// { dg-skip-if "requires hosted libstdc++ for cassert" { ! hostedlib } } |
| 3 |
|
| 4 |
#include <cassert> |
| 5 |
|
| 6 |
constexpr int n = 10; |
| 7 |
|
| 8 |
struct A { |
| 9 |
constexpr operator const int*() const { |
| 10 |
return data; |
| 11 |
} |
| 12 |
|
| 13 |
constexpr operator int*() { |
| 14 |
return data; |
| 15 |
} |
| 16 |
|
| 17 |
private: |
| 18 |
int data[n]; |
| 19 |
}; |
| 20 |
|
| 21 |
constexpr A f() { |
| 22 |
A a{}; |
| 23 |
for (int i = 0; i < n; i++) { |
| 24 |
a[i] = i; |
| 25 |
} |
| 26 |
return a; |
| 27 |
} |
| 28 |
|
| 29 |
A a = f(); |
| 30 |
|
| 31 |
int main() |
| 32 |
{ |
| 33 |
for (int i = 0; i < n; i++) { |
| 34 |
assert (a[i] == i); |
| 35 |
} |
| 36 |
} |