https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103954
Bug ID: 103954 Summary: GCC did not generate correct code for template function with O2 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: woodhead99 at gmail dot com Target Milestone: --- Created attachment 52147 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52147&action=edit gcc version, command line option, .ii file and a detailed issue description I have encountered an optimization issue with O2 option. A variable is expected to change after a function call. but the compiler did not generate the function correctly, more precisely the function is an inline function, which calls a template function, but the code for the inner template function was not generated. The compiler seems to assume the variable keep unchanged through the call, and optimized out the template function body. This issue happens only with O2 option. O0 and O1 are OK.