https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104635
Bug ID: 104635 Summary: for loop optimized into infinite loop Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: szullo.adam at gmail dot com Target Milestone: --- compiling with g++, optimization (other than -O0) turn for loop into infinite loop #include <stdio.h> int test() { for (int i=0; i<4; i++) { printf("%d\n",i); } } int main() { test(); } i DO ACKNOWLEDGE, that (contrary to c) in c++ missing return value is invalid (-Wreturn-type) Expected behaviour: return with garbage value -or- segfault on return // or maybe instead of warning, throw error