https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106965
Bug ID: 106965 Summary: g++ optimization removes assigning 0 to deleted pointer- causes double free. Product: gcc Version: 11.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: olddra3rd at mozmail dot com Target Milestone: --- Created attachment 53590 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53590&action=edit source file of the function implementations. Dear GNU, how are you? Using gcc version 11.2.0 (Ubuntu 11.2.0-19ubuntu1) on a Ubuntu 22.04, received a double free after using a destructor twice (one explicitly and one at the end of function) with compiling optimizations.. Comp Bug occurs when when the call happens on a different compilation unit: int main() { X x1; x1.~X(); return 0; } >From looking at the assembly - it seems assigning 0 to the pointer is removed from the code. Compilation flags: g++ -O Seems to work fine with clang++. Have a great day!