dimanche 10 septembre 2017

Inheriting constexpr variadic constructor in MSVC

The following code is rejected by MSVC 15.4.0 Preview 1 (VS 2017), but is accepted by GCC 7.1.0.

struct B {
    template<typename... Ts>
    constexpr B(Ts... data)
        : data_{data...}
    {}

    int data_[5];
};

struct D : B {
    using B::B;
};

constexpr /*B*/ D g() {
return /*B*/ D(4, 5, 6);
}

int main() {
    constexpr auto z = g();
}

The error is: Error C3615 constexpr function 'g' cannot result in a constant expression. If I construct and return B, everything is fine.

Is it a bug in the MSVC compiler?

Aucun commentaire:

Enregistrer un commentaire