Date: Thu, 19 Nov 2026 10:07:17 -0500
On Thu, Nov 19, 2026 at 4:20 AM Cell via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> 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
> <https://eel.is/c%2B%2Bdraft/class.mem#general-10>*] 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.
>
Recently on my blog:
https://quuxplusone.github.io/blog/2026/08/25/size-idioms/
I have no special knowledge here, but it seems to me that you might run
into confusing logic with things like
struct X {
static constexpr int f(unsigned) { return 1; }
static constexpr int m_foo = X::f(0); // Ill-formed today. On
first scan-through, by this point only f(unsigned) is visible; if we wait
until X is complete, we'll call f(int) instead; surely we want the latter,
right?
static constexpr int f(int) { return 2; }
};
And, more to the point, circular logic with things like
struct X {
static constexpr int m_size = 42;
int m_data[m_size]; // Well-formed today. If we wait until X is
complete to figure out m_size's value, then wouldn't this become ill-formed?
static constexpr int m_bar = sizeof(X); // Ill-formed today; but
if it were well-formed, it would certainly need to know sizeof(m_data)
already
};
Namely
struct X {
static constexpr int m_size = sizeof(X);
char m_data[m_size + 1]; // What happens here??
};
Cheers,
Arthur
std-proposals_at_[hidden]> wrote:
> 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
> <https://eel.is/c%2B%2Bdraft/class.mem#general-10>*] 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.
>
Recently on my blog:
https://quuxplusone.github.io/blog/2026/08/25/size-idioms/
I have no special knowledge here, but it seems to me that you might run
into confusing logic with things like
struct X {
static constexpr int f(unsigned) { return 1; }
static constexpr int m_foo = X::f(0); // Ill-formed today. On
first scan-through, by this point only f(unsigned) is visible; if we wait
until X is complete, we'll call f(int) instead; surely we want the latter,
right?
static constexpr int f(int) { return 2; }
};
And, more to the point, circular logic with things like
struct X {
static constexpr int m_size = 42;
int m_data[m_size]; // Well-formed today. If we wait until X is
complete to figure out m_size's value, then wouldn't this become ill-formed?
static constexpr int m_bar = sizeof(X); // Ill-formed today; but
if it were well-formed, it would certainly need to know sizeof(m_data)
already
};
Namely
struct X {
static constexpr int m_size = sizeof(X);
char m_data[m_size + 1]; // What happens here??
};
Cheers,
Arthur
Received on 2026-11-19 15:07:33
