Is S related to X?
 

-----Ursprüngliche Nachricht-----
Von: Cell via Std-Proposals <std-proposals@lists.isocpp.org>
Gesendet: Do 19.11.2026 10:20
Betreff: [std-proposals] Complete-class contexts for inline static data member initializers
An: std-proposals@lists.isocpp.org;
CC: Cell <dicot0721@gmail.com>;

Hello,

I would like to discuss whether in-class initializers of inline static data members should be considered complete-class contexts.

Currently, [class.mem.general] treats function bodies and default member initializers as complete-class contexts, but not static data member initializers. This creates some restrictions even though C++17 allows inline static data members to be defined and initialized within a class.

For example, I would like the following to be well-formed:

struct X {     static constexpr std::size_t m_foo = alignof(S);
    static constexpr std::size_t m_bar = bar();
    static inline std::size_t m_baz = m_foo * 2;
    static inline int m_qux = qux();
 
    static consteval std::size_t bar() {
        return sizeof(S) * 2;
    }
    static int qux() {
        return 0;
    }
};

Ideally, all inline static data member initializers permitted within a class definition would be able to use the complete enclosing class, while retaining the existing requirements for constant expressions and the existing initialization-ordering rules.

Are there fundamental semantic or implementation concerns with such an extension?

I would appreciate any thoughts or references to previous discussions.

Thanks.

-- 
 Std-Proposals mailing list
 Std-Proposals@lists.isocpp.org
 https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals