https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106526
Bug ID: 106526 Summary: array-bounds warning on constant pointer dereferencing Product: gcc Version: 12.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: wrenger at sra dot uni-hannover.de Target Milestone: --- On optimization levels 2 and 3 the GCC frontend emits false array-bounds warnings when dereferencing constant pointers. # Example CFLAGS: -O2 -Wall -Werror ``` int main(void) { int ebda = *((int*)(0x40e)); return ebda; } ``` The following error only occurs on GCC 12.1 and newer. ``` <source>: In function 'main': <source>:2:16: error: array subscript 0 is outside array bounds of 'int[0]' [-Werror=array-bounds] 2 | int ebda = *((int*)(0x40e)); | ^~~~~~~~~~~~~~~~ cc1: all warnings being treated as errors ``` > See: https://godbolt.org/z/Kff744P58