<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/116444>116444</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-static-analyzer: Aggregate-initialized struct field incorrectly marked undefined
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rojer
</td>
</tr>
</table>
<pre>
This code:
```cpp
#include <iostream>
#include <string>
struct Structy {
std::string foo;
int bar;
};
int main() {
auto *s = new Structy{
.foo = "foo",
.bar = 1,
};
std::cout << s->foo << s->bar;
delete s;
}
```
produces the following static analyzer warning:
```
$ clang-tidy -p . test.cpp
1 warning generated.
/home/rojer/allterco/shelly-ng3/qq.cpp:14:3: error: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage,-warnings-as-errors]
14 | std::cout << s->foo << s->bar;
| ^ ~~~~~~
/home/rojer/allterco/shelly-ng3/qq.cpp:10:13: note: Uninitialized value stored to field 'bar'
10 | auto *s = new Structy{
| ^~~~~~~~~~~~
11 | .foo = "foo",
| ~~~~~~~~~~~~~
12 | .bar = 1,
| ~~~~~~~~~
13 | };
| ~
/home/rojer/allterco/shelly-ng3/qq.cpp:14:3: note: 1st function call argument is an uninitialized value
14 | std::cout << s->foo << s->bar;
| ^ ~~~~~~
1 warning treated as error
```
`s->bar` is of course explicitly initialized to 1, so the generated warning is a false-positive.
swapping field order to bar, foo makes it go away.
tested with latest main (20.0.0git ec353b7418e272e96cd63cc61bec586ab49da92f).
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVc2S4yYQfhp86ZJKAsmyDjp47fEtpyQPgKAlk8WgBTQT72GePQX-kZ1yKqkJ5cISTf993f2Je69Gg9iR-hup9ys-h6N1nbN_oFv1Vp67347Kg7ASCduSYk-K274uLj8xTdcTypQRepYIhO2U9cEhPxH29krsg1NmXIRp98HNIsCv6e8MpPl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