https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85914
Bug ID: 85914 Summary: -Wreturn-type false positive with tautological ternery Product: gcc Version: 7.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: Anderson.Ku at synopsys dot com Target Milestone: --- $uname -a Linux anku-Z440 4.4.0-109-generic #132-Ubuntu SMP Tue Jan 9 19:52:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux $g++ --version g++ (GCC) 7.1.0 $g++ /u/anku/test.cpp -c -Wreturn-type /u/anku/test.cpp: In function 'int processDMInitActivity(int)': /u/anku/test.cpp:16:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ Adding -O1, -O2, or O3 removes the warning isolated code: __attribute__((noreturn)) void throw_assert(); struct MyClassWithVirtualDtor{ virtual ~MyClassWithVirtualDtor(); }; int processDMInitActivity(int x) { MyClassWithVirtualDtor mcf; if(x) { return -1; } false ? void(0) : throw_assert(); // This also warns // false ? void(0) : throw 303; }