https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110534
Bug ID: 110534
Summary: confusing -Wuninitialized when strict aliasing is
violated
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: vanyacpp at gmail dot com
Target Milestone: ---
GCC gives -Wuninitialized on this code:
#include <cstdint>
uint16_t test()
{
uint32_t foo32[4] = {0, 0, 0, 0};
uint16_t* foo16 = reinterpret_cast<uint16_t*>(&foo32[0]);
return foo16[0];
}
<source>:7:19: warning: 'foo32' is used uninitialized [-Wuninitialized]
7 | return foo16[0];
| ^
<source>:5:14: note: 'foo32' declared here
5 | uint32_t foo32[4] = {0, 0, 0, 0};
| ^~~~~
This issue was originally published on reddit:
https://www.reddit.com/r/cpp/comments/14lc9w9/gcc_warnings_for_uninitialized_variables_is/
The poster found the warning quite confusing and I agree with them.
I believe the ideal behavior would be to show -Wstrict-aliasing on this code
and avoid showing -Wuninitialized.