Description of problem: The following code snippet spits a warning with gcc-7.1.1-3.fc26 and -Wall on ppc64le AND x86_64, while we would expect the compiler to optimize the loop away since the array is empty. int foo(void) { char empty_array[] = { }; int i, ret = 0; for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) { ret = empty_array[i]; } return ret; } Version-Release number of selected component (if applicable): gcc-7.1.1-3.fc26 How reproducible: Always. Steps to Reproduce: 1. cat>foo.c<<EOF int foo(void) { char empty_array[] = { }; int i, ret = 0; for (i = 0; i < (int) (sizeof(empty_array) / sizeof(empty_array[0])); i++) { ret = empty_array[i]; } return ret; } EOF 2. gcc -c -Wall foo.c 3. Actual results: foo.c: In function ‘foo’: foo.c:7:26: warning: ‘empty_array[i]’ may be used uninitialized in this function [-Wmaybe-uninitialized] ret = empty_array[i]; Expected results: No warning. Additional info: This doesn't happen on fedora24 (gcc-6.3.1-1.fc24) or fedora25 (gcc-6.4.1-1.fc25). This code pattern is used in QEMU, and causes the build to fail because we pass -Wall -Werror to gcc by default.
Also note that removing the '(int)' cast is enough to silence the warning; no idea why the cast is confusing the compiler.
Thanks for the report, I've opened PR81782.
This is now fixed on trunk.
gcc-7.3.1-5.fc27.x86_64 doesn't warn anymore, closing.