<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/156781>156781</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Spurious `-Wuninitialized` warning when referring to a previously initialized member of an aggregate inside an initializer list
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
akbyrd
</td>
</tr>
</table>
<pre>
This code:
```
struct Bar
{
int get() { return 1; }
};
struct Foo
{
Bar x;
int y;
};
int main()
{
Foo f = {
.x = {},
.y = f.x.get() + 1,
};
return f.y;
}
```
Causes this warning:
```
warning: variable 'f' is uninitialized when used within its own initialization [-Wuninitialized]
```
https://godbolt.org/z/6hhajcxYG
As far as I can tell, this is well defined and should not issue a warning. `Foo` is an aggregate and initialization expressions in a list initializer are sequenced. Neither GCC nor MSVC warn on this construct. Clang itself does not warn on other similar forms of this, such as:
```
struct Foo
{
int x;
int y;
};
int main()
{
Foo f = {
.x = {},
.y = f.x + 1,
};
return f.y;
}
````
https://godbolt.org/z/od7MWYx1T
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzElL-O4zYQxp-GagYrUJQtrQoV_gMdUlyaO-Rw5YgcSbzQpENSu_Y9fUDZXns3CVKkCGDYFvnN8JvRb4gh6NEStWy9Zet9hnOcnG_x9_7sVdY7dW6_TjqAdIpYuWF8wyp-_fBNiH6WEbbo00a9Td-80TbCSJGJZyYaYPUWPMXZWyhYuQVW7xfxnpUX_S1L59xjli16ON00S87z9ekhNC0fUNvLWY_hnXMwACv38LbEeJOf3pbqPRO7-8Z52RjyU_5gXWyhuKsezmW8udY05A-23neH8c0O50ABYmrhK3qr7fjXLt434AW9xt4QMFEPTNSgA8xWWx01Gv2TFLxOZGEO6Z-Ok7agYwD3auFNhFE7C2y9ffr2LpSt_8bgFOMxJEuiY6IbneqdibnzIxPdTya6aprwhzx9_3SRbwIM6AED_AISLUQyhondpcBUIxkDigZtSQFaBWFys1FgXQQdwkyAtz7kwCqe3nnFUyRawHH0NGKkJfJDPXQ6egpBOxtAW0AwOsS7iDygJwj0x0xWksrhV9JxIg-fdjuwzsPnL7_tlrPB2Ytf6ewFvRx2Bu2YWklmAOUoLI5varckCvqgDXoYnD8EcMOSJBUfZjkBhn8cjw9gJ2b_D7D_G85LQf9Gi1P152_fT8XXTLWlasoGM2qLel01q7psimxq6wYLFKKsUNSlrFcDbypOshZ1reRKNZluBRdr3vAV5-uqLPJVMZRKSvlcoZR9z9mK0wG1yY15OaSzswWstlhX9XORGezJhOU6E8LS6wU7JkS63Xybgp76eQxsxRNB4Z4m6mio_XKcvXZzSHR-HKCK3-C9jKGngbxPj9EBwtHTSwo1Z3ic2AMdevIJmHeMaxu0Sqi_gzh5ymZv2g-t1nGa-1y6AxNdcnz9eTp694NkZKJb6gxMdNdGvLTizwAAAP__Ka7Edw">