https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87515

            Bug ID: 87515
           Summary: "no return statement in function returning non-void"
                    miscompiles with optimizations
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jaydee at email dot cz
  Target Milestone: ---

Happens with gcc version 8.2.0 (Debian 8.2.0-7), standalone near-minimal
testcase:

#include <iostream>
using namespace std;

int blam(int x) {
        if (x!=0) {
                cout << x << " != 0" << endl;
        }
}

int main() {
        blam(0);
        blam(1);
}

Expected behavior: prints 1 != 0, this actually happens without optimizations.
Unexpected behavior happens with optimizations enabled (-O is enough): it
prints nothing.

I realize that the code is not fully valid, but the resulting behavior is
surprising to say the least. Or the warning should be an error instead. We have
found some variants along the same lines in our codebase that print the
equivalent of 0!=0 and/or segfault.

Reply via email to