const
variable can't be modified after initialization, otherwise it's undefined behavior.
Since it is undefined behavior, I think one can say both gcc and clang follow the standard. (Although gcc's choice seems better, it deserves a warning) (See EDIT below)
The only way to give the variable x
a value with defined behavior is to initialize it:
SX sx = { .x = 10 };
EDIT: As @Keith Thompson comments below, it's more than just undefined behavior in this case:
C99 §6.5.16 Assignment operators
Constraints
An assignment operator shall have a modifiable lvalue as its left operand.
This is a constraint, and according to:
C99 §5.1.1.3 Diagnostics
A conforming implementation shall produce at least one diagnostic message (identified in
an implementation-defined manner) if a preprocessing translation unit or translation unit
contains a violation of any syntax rule or constraint, even if the behavior is also explicitly specified as undefined or implementation-defined. Diagnostic messages need not be produced in other circumstances.
A compiler must issue a diagnostic for any program that violates a constraint.
Back to the question, gcc is correct is generate a warning, while clang fails to do so.