summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp1y/constexpr-66093.C
blob: ad3169210d29a41137f51aceea5516a6c042cb3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// { dg-do run { target c++14 } }

#include <cassert>

constexpr int n = 10;

struct A {
    constexpr operator const int*() const {
        return data;
    }
  
    constexpr operator int*() {
        return data;
    }
  
private:
    int data[n];
};

constexpr A f() {
    A a{};
    for (int i = 1; i <= n; i++) {
        a[i] = i;
    }
    return a;
}

A a = f();

int main()
{
    for (int i = 0; i < n; i++) {
        assert (a[i] == i);
    }
}