https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108576
Bug ID: 108576 Summary: False positive for -Werror=return-type Product: gcc Version: 12.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sergey at polovko dot me Target Milestone: --- Starting from GCC 12.1 I see changed compiler behaviour for following snippet of code: struct S { ~S() {} }; int func() { if (auto s = S{}; false) { } else { return 1; } } >From GCC 7.1 to 11.3 this snippet of compiled just fine: * https://godbolt.org/z/Yb787e6cs (7.1) * https://godbolt.org/z/8Gq4fjacr (12.3) But starting from GCC 12 it produces a warning: * https://godbolt.org/z/MvoTcb7aW (12.1) * https://godbolt.org/z/dvqebv7KG (trunk) $ g++ -std=c++17 -Werror=return-type <source>: In function 'int func()': <source>:10:1: error: control reaches end of non-void function [-Werror=return-type] 10 | } | ^ cc1plus: some warnings being treated as errors Compiler returned: 1 The issue appears only with default or -O0 optimization level. With -O1 there is no warnings: * https://godbolt.org/z/Pxv1Ms5ez $ g++ -std=c++17 -O1 -Werror=return-type