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
_______________________________________________
devel mailing list -- devel@lists.fedoraproject.org
To unsubscribe send an email to devel-le...@lists.fedoraproject.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: 
https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org

Reply via email to