Background
Big C++17 project which is build for multiple platforms. Have to support MSVC, clang and gcc
Problem
Following code fails on MSCV and it is fine for other compilers.
#include <algorithm>
#include <initializer_list>
#define FOO_1 1
#define FOO_2 2
#define FOO_3 3
class Baz {
static constexpr auto data = {FOO_1, FOO_2, FOO_3};
static constexpr auto copy_max = std::max({FOO_1, FOO_2, FOO_3});
static constexpr auto data_max = std::max(data);
void bar(std::initializer_list<int>);
void test();
};
void Baz::test()
{ bar(data); }
https://godbolt.org/z/7nv3z3rMY
FOO_x macros comes for external library. Baz is my code.
Now I need data_max for some logic and I whish to calculate that at compile time.
As a workaround I've introduce copy_max which is initialized by duplicate code which is bad (there are lots of values and list can be changed), also data are used in runtime code.
Apparently problem is present only for msvc 19.29 (installed on my machine) older version do not have this issue.
Question
Is there a way to somehow overcome this problem without using extra macros or duplicating code? I've try to use std::max_element, which is constexpr since C++17, with same outcome.
Is this a know bug or should I file new one?