Issue 1023: static_assert in structure and union definitions

Authors: Jay Ghiron
Date: 2026-02-17
Submitted against: C23
Status: Open

The standard syntactically allows the following structure definition:

struct S{int x;static_assert(sizeof(int)==4);};

However, it appears to violate the following constraint (C23 6.7.3.2 "Structure and union specifiers" paragraph 2):

A member declaration that does not declare an anonymous structure or anonymous union shall contain a member declarator list.

It seems unintended to syntactically allow static_assert while forbidding it. A second issue with this constraint is that it does not forbid:

struct A{int y;struct B{struct{int z;};};};

Since the member declaration struct B{struct{int z;};}; does declare an anonymous structure, just not one within A. I assume that this is not intended, however.

Considering "The optional attribute specifier sequence in a member declaration appertains to each of the members declared by the member declarator list; it shall not appear if the optional member declarator list is omitted." (C23 6.7.3.2 paragraph 9) and "Except where the type is inferred (6.7.10), at least one type specifier shall be given in the declaration specifiers in each declaration, and in the specifier-qualifier list in each member declaration and type name." (C23 6.7.3.1 paragraph 2) also use the phrase "member declaration" to not include static_assert declarations, a correction can separate static_assert-declaration from member-declaration instead of changing each of the uses of "member declaration".

A correction to the second issue should be done similar to C23 6.7.1 paragraph 2, except that it requires the absence of a tag. That wording is not perfect either, adding examples to clarify the intent would be useful in 6.7.3.2 as well.


Comment from Issues list maintainer on 2026-08-21:

This issue was discussed at the August 2026 (Ottawa) meeting of WG14. Joseph Myers took an action item to propose wording with a minimal correction to exclude static_assert declarations from this constraint, while Martin Uecker took an action item to write a paper allowing unnamed members more generally (with it being noted in discussion that it would be necessary to check whether implementations are consistent in how they handle such members, and in particular whether there are variations in the size of a structure or union among those that accept them).


Comment from Issues list maintainer on 2026-08-25:

In reflector message 37699, Joseph Myers proposed wording for this issue.

In C23 6.7.3.2 (Structure and union specifiers), change:

A member declaration that does not declare an anonymous structure or anonymous union shall contain a member declarator list.

to

If a member declaration other than a static_assert declaration does not include a member declarator list, its specifier qualifier list shall include a structure or union specifier with no tag.

In C23 6.7.3.2 (Structure and union specifiers), also change:

The member declaration list is a sequence of declarations for the members of the structure or union, possibly mixed with static_assert declarations.

In C23 3.17 (definition of "memory location"), change:

The same applies to two bit-fields, if one is declared inside a nested structure declaration and the other is not, or if the two are separated by a zero-length bit-field declaration, or if they are separated by a non-bit-field, non-static_assert member declaration.