issue with constexpr and CRTP

Viewed 98

I'm having the following issue with constexpr arrays and CRTP. While the first line works the second yields an error that Der::arr does not exist. Given that the first line should execute in a constexpr context, I'm not sure what the issue is with the second.

template <typename Der>
struct Base
{   
    static constexpr std::size_t val = Der::arr.size(); // This works
    static constexpr std::array<int, Der::arr.size()> r = {}; // yields error
};

struct Derived : Base<Derived>
{
    static constexpr std::array<int, 10> arr = {};
};

int main(int argc, char **argv){
    Derived d;  
    return d.val;
}

Error:

<source>:12:43: error: no member named 'arr' in 'Derived'
    static constexpr std::array<int, Der::arr.size()> r = {}; // yields error
                                     ~~~~~^
<source>:15:18: note: in instantiation of template class 'Base<Derived>' requested here
struct Derived : Base<Derived>
                 ^
1 error generated.
Compiler returned: 1
0 Answers
Related