https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117246
Bug ID: 117246 Summary: g++ O1 finline bug Product: gcc Version: 12.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wso4133560 at gmail dot com Target Milestone: --- This is my example code: #include <iostream> class Test { public: static void* operator new(std::size_t count, int value) { std::cout << __LINE__ << " " << value << std::endl; Test *test = static_cast<Test *>(malloc(count)); //Test * volatile test = static_cast<Test *>(malloc(count)); test->value = value; return test; } Test() { std::cout << __LINE__ << " " << value << std::endl; } public: int value; }; int main(int argc, char *argv[]) { Test *test = new(1) Test{}; std::cout << __LINE__ << " " << test->value << std::endl; delete test; return 0; } I used command "g++ error.cpp -O0 -o error", get result: 8 1 17 1 27 1 I used command "g++ error.cpp -O1 -fno-inline -o error", get result: 8 1 17 1 27 1 I used command "g++ error.cpp -O1 -o error", get result: 8 1 17 0 27 0