https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118403
Bug ID: 118403 Summary: uninitialized warning with automatic union Product: gcc Version: 15.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stephen at networkplumber dot org Target Milestone: --- Building DPDK project with GCC 15 gets a new warning in one of the drivers. Which does not occur with GCC 14. In function ‘nicvf_mbox_send_msg_to_pf_raw’, inlined from ‘nicvf_mbox_send_async_msg_to_pf’ at ../drivers/net/thunderx/base/nicvf_mbox.c:70:2, inlined from ‘nicvf_mbox_link_change’ at ../drivers/net/thunderx/base/nicvf_mbox.c:477:2: ../drivers/net/thunderx/base/nicvf_mbox.c:59:17: warning: ‘mbx’ is used uninitialized [-Wuninitialized] 59 | nicvf_reg_write(nic, mbx_addr, *mbx_data); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../drivers/net/thunderx/base/nicvf_mbox.c: In function ‘nicvf_mbox_link_change’: ../drivers/net/thunderx/base/nicvf_mbox.c:474:24: note: ‘mbx’ declared here 474 | struct nic_mbx mbx = { .msg = { 0 } }; | If the initialization is replaced by an empty expression struct nic_mbx mbx = { }; Then there is no warning. The data structure in question looks like: struct nic_mbx { /* 128 bit shared memory between PF and each VF */ union { struct { uint8_t msg; } msg; struct nic_cfg_msg nic_cfg; struct qs_cfg_msg qs; struct rq_cfg_msg rq; struct sq_cfg_msg sq; struct set_mac_msg mac; struct set_frs_msg frs; struct cpi_cfg_msg cpi_cfg; struct rss_sz_msg rss_size; struct rss_cfg_msg rss_cfg; struct bgx_link_status link_status; struct sqs_alloc sqs_alloc; struct set_loopback lbk; struct reset_stat_cfg reset_stat; struct set_link_state set_link; struct change_link_mode_msg mode; struct xcast xcast; }; }; My understanding is that both should be equivalent. Reference C99 Standard 6.7.8.21: If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration Tried to make simple example, but it was hard to reproduce.