On Tue, Jan 29, 2019 at 01:04:25PM +0000, Daniel P. Berrangé wrote:
The variable was already initialized right at the start. The
compound
literal is just a short-hand for later changing the values in several
fields of the struct at once. This is no different to manually assigning
new values to each individual field one at a time. eg
struct demo demo = {0};
...some code with a goto...
demo = (struct demo) { .cmd = "foo" };
No, I wasn't talking about the demo variable, the warning is not about demo
variable. The warning is about the compound literal variable.
That is an anonymous (when used at block scope automatic) variable, kind
like:
struct demo __complit = { .cmd = "foo" };
demo = __complit;
and with the goto you are crossing initialization of that variable.
When you aren't taking address of this, the optimizers will likely optimize
the temporary away later on, if you'd do &(struct demo) { .cmd = "foo"
}
that address could be used later on in the function, dereferenced etc.
Jakub