Код: Выделить всё
#include
struct A {
int a;
bool b;
using T1 = int A::*;
using T2 = bool A::*;
using U = std::variant;
static constexpr const U Ptrs[] = {
{&A::a}, {&A::b}
};
};
< /code>
vs output: < /p>
(23): error C2327: 'A::a': is not a type name, static, or enumerator
(23): error C2065: 'a': undeclared identifier
(23): error C2327: 'A::b': is not a type name, static, or enumerator
(23): error C2065: 'b': undeclared identifier
(24): fatal error C1903: unable to recover from previous error(s); stopping compilation
Код: Выделить всё
struct A {
int a;
bool b;
using T1 = int A::*;
using T2 = bool A::*;
template
union MyUn {
T1 pA;
T2 pB;
constexpr MyUn(T1 a) : pA(a) {}
constexpr MyUn(T2 b) : pB(b) {}
};
using U = MyUn;
static constexpr const U Ptrs[] = {
{&A::a}, {&A::b}
};
};
< /code>
, который кажется законным и поддерживается GCC: < /p>
:22:5: error: 'constexpr A::MyUn::MyUn(T1) [with T1 = int A::*; T2 = bool A::*]' used before its definition
struct B : A {
static constexpr const U Ptrs[] = {
{&A::a}, {&A::b}
};
};
< /code>
Но GCC 15.1 отклоняет следующий код для любых типов T1 и T2: < /p>
Код: Выделить всё
struct B : A {
template
union MyUn {
T1 pA;
T2 pB;
constexpr MyUn(T1 a) : pA(a) {}
constexpr MyUn(T2 b) : pB(b) {}
};
using U = MyUn;
static constexpr const U Ptrs[] = {
{T1()}, {T2()}
};
};
Подробнее здесь: https://stackoverflow.com/questions/797 ... pr-context
Мобильная версия