MSVC error on constexpr std::array of pointer to constexpr variables, while other compilers don't

Viewed 80

Declaring a constexpr variable which value is a constexpr std::array of pointers to other constexpr variables MSVC gives an error (C2440), where Clang and GCC seems to accept the code.

Moving the array to a local scope, changing the standard or using MSVC x86 doesn't change anything.

The only version that doesn't give this error is 19.14 (which is the oldest one available on compiler explorer for MSVC).

Is this behavior a bug from Microsoft or is it normal/in the standard ?

Here is the repro: (in compiler explorer https://godbolt.org/z/qnW1j9Y33)

#include <array>

static constexpr
int an_int1 = 1;

static constexpr
int an_int2 = 2;

static constexpr
int an_int3 = 3;

static constexpr
std::array<const int *, 3> the_array = {&an_int1, &an_int2, &an_int3};

int main()
{
    constexpr std::array<const int *, 3> a = the_array;
    constexpr decltype(the_array) b = the_array;
    constexpr auto c = the_array;
    return 0;
}
0 Answers
Related