Подтвердить что ты не робот

Странное поведение constexpr для внутреннего класса

Кто-нибудь может это объяснить?

template<typename T, size_t S = T::noElems()>
struct C
{
};

struct X
{
    enum E { A, B, C };
    static constexpr size_t noElems() { return C+1; };
};

struct K
{
    C<X> cx; // this DOES compile
};

struct Y
{
    struct Z
    {
        enum E { A, B, C };
        static constexpr size_t noElems() { return C+1; };
    };
    C<Z, Z::C+1> cyz; // this DOES compile

    C<Z> cyz; // <--- this does NOT compile 
};
4b9b3361

Ответ 1

С объявлением структуры

struct Y
{
    struct Z
    {
        enum E { A, B, C };
        static constexpr size_t noElems() { return C+1; };
    };
    C<Z, Z::C+1> cyz1; // this DOES compile

    C<Z> cyz2; // <--- this does NOT compile 
};

объекты cyz1 и cyz2 анализируются перед встроенным объявлением Z::noElems(), поэтому определение

static constexpr size_t noElems() { return C+1; };

недоступен во время объявления

C<Z> cyz2;