C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Complete-class contexts for inline static data member initializers

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 19 Nov 2026 11:48:01 +0100
Is S related to X?   -----Ursprüngliche Nachricht----- Von:Cell via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Do 19.11.2026 10:20 Betreff:[std-proposals] Complete-class contexts for inline static data member initializers An:std-proposals_at_[hidden]; CC:Cell <dicot0721_at_[hidden]>; 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_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2026-11-19 10:49:44