https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110263
Bug ID: 110263
Summary: Bogos Warning [-Wreturn-type] for unreachable code
Product: gcc
Version: 13.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: gerstner.thomas at siemens dot com
Target Milestone: ---
The following example (see https://gcc.godbolt.org/z/4477zajnj) produces
Warning [-Wreturn-type]:
bool foo();
int instrumentation = 0;
struct S { ~S(); };
int func() {
S s; // if commented out there is no warning [-Wreturn-type]
while(true) { // "endless loop"
if (foo()) return 42;
}
instrumentation++; // if commented out there is no warning [-Wreturn-type]
}
Our original code is without the line "instrumentation++;", because this line
is an additional instrumentation by a tool (Squish Coco).
We made [-Wreturn-type] an error and therefor our build fails.
If this example is build with "-O2" the warning is gone.
This problem is very similar to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67693 which seems to be fixed but
it's not identical.