Этот минимальный пример
Код: Выделить всё
#include
constexpr int f() {
union U {
char x{0};
int y;
} u;
std::construct_at(&u.y, u.x);
return u.y;
}
static_assert( f() == 0 );
Код: Выделить всё
/opt/compiler-explorer/clang-19.1.0/bin/../include/c++/v1/__memory/construct_at.h:41:50:
note: read of member 'x' of union with active member 'y' is not allowed in a constant expression
41 | return ::new (std::__voidify(*__location)) _Tp(std::forward(__args)...);
Какая реализация здесь правильная?
Подробнее здесь: https://stackoverflow.com/questions/791 ... nstruct-at
Мобильная версия