MSVC 2017 Community with -std=c++17
chokes on the following example:
#include
struct TC
{
static TC const values[];
static
I isolate the same problem to this simpler example:
#include <iostream>
int values[3];
constexpr int& v{ values[1] };
int main()
{
std::cout << &v << ", " << &values[1] << "\n";
return 0;
}
which, using latest MSVC 2017 Community, gives output of:
0119D035, 0119D038
The problem does not happen if constexpr
is removed.
So I think this is a compiler bug with constexpr
reference initialization. The reference was initialized to &values[0]
+ 1 byte, not &values[1]
as it should be.
NB. If anyone is not familiar with constexpr
reference definitions, see here or here. constexpr
enforces that the initializer is an object with static storage duration.