lundi 22 mai 2017

Not compile-time constant expression in VS2017

VS2017 15.1 fails to compile the following code:

template<int data_size>
struct Data { };

template<int s>
struct Base
{
    static constexpr int size() { return s; }
};

template<int s>
struct Derived : Base<s>   // struct Derived
{
    Data<Base<s>::size()> data;
};

int main()
{
    Derived<1> c;
}

The error is:

error C2975: 'data_size': invalid template argument for 'Data', expected compile-time constant expression
note: see declaration of 'data_size'
note: see reference to class template instantiation 'Derived<s>' being compiled

If I do not derive Derived from Base, the error disappears. With gcc 5.4.0 and clang 4.0.0 everything is fine in both cases.

Is anything wrong with this code?

Aucun commentaire:

Enregistrer un commentaire