Thanks everyone for the comments!
First, a side point:
It's a pretty odd use of literals. I would have never thought of doing that.
I see that many, as SiliconWizard, did not like the style.
No problem with that, it's to a large extent personal - to me it's more readable than having a uselessly declared variable, I make extensive use of compound literal when a variable name is not needed, mostly in two cases: as (struct *, usually) arguments to a function and the one we are discussing.
About the modifiability of lvalues (brucehoult, AntiProtonBoy, SiliconWizard): non modifiable lvalues in C are a specific subset, and outside of its constraints lvalues are in general modifiable.
6.3.2.1 Lvalues, arrays, and function designators
...
A modifiable lvalue is an lvalue that does not have array type, does not have an incomplete type, does not have a const-qualified type, and if it is a structure or union, does not have any member (including, recursively, any member or element of all contained aggregates or unions) with a const-qualified type.
In my case the unnamed static object is not an array type (a moot point, its elements would still be modifiable, as in the example the standard provides), it is not const-qualified, and it does not have any const-qualified member, so it is by default modifiable.
C++ is, as usual, much more complicated, but lacks compound literals - so I cannot directly compare the standards (though clang implements them as an extension, see the issue mentioned at the end).
attempting to modify a constant
This not what I'm doing. I'm trying to modify a non const-qualified static object, albeit an unnamed one, through a const-qualified pointer to a non-const-qualified type.
For static duration objects the initializers must be constant expression or string literals, but of course this does not prevent us to do:
static int i=42;
void f(void)
{
i = 0;
}You are taking an address of a temporary object. The pointer to the struct becomes an invalid address soon after the assignment operator, because the struct instance was stored in some implementation defined temporary memory which is immediately "freed".
The unnamed object has static storage duration, it is
not temporary, as per "6.5.2.5 Compound literals", §5:
If the compound literal occurs outside the body of a function, the object has static storage duration;
I'll open an issue on LLVM GitHub repo - let's see what they think.
I've searched past issues with no luck, with the exception of
this, which might be somehow relevant.
Ataradov, I'll use your minimal example, thanks again.
EtA: The issue can be found
here