Код: Выделить всё
#include
struct A {
int i;
};
struct B {
constexpr explicit B(int) {}
};
struct C {
int v;
constexpr C(std::initializer_list) : v(1) {}
constexpr C(std::initializer_list) : v(2) {}
};
static_assert( C{{1}}.v == 1 );
Однако GCC жалуется: < /p>
Код: Выделить всё
error: call of overloaded 'C(
)' is ambiguous
note: candidate: 'constexpr C::C(std::initializer_list)'
note: candidate: 'constexpr C::C(std::initializer_list)'
< /code>
и MSVC: < /p>
error C2440: '': cannot convert from 'initializer list' to 'C'
note: No constructor could take the source type, or constructor overload resolution was ambiguous
Какой компилятор здесь правильный? И теперь Clang, MSVC и EDG все принимают программу, и только GCC продолжает отвергать ее. Демо: https://gcc.godbolt.org/z/83ejvs49x
Подробнее здесь: https://stackoverflow.com/questions/710 ... lizer-list
Мобильная версия