[llvm-bugs] [Bug 35517] New: Delete called in virtual destructor

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 4 06:27:54 PST 2017


https://bugs.llvm.org/show_bug.cgi?id=35517

            Bug ID: 35517
           Summary: Delete called in virtual destructor
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: moko at design.ru
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

The following code produces link error with all available to us clang versions.
It compiles when destructor is not virtual. Note that there is no "new"
operator calls, only "delete" is called. The code also compiles with gcc
starting with version 6.1.

--------------------------------------

/tmp/example-d524df.o: In function `operator delete(void*)':
23 : <source>:23: undefined reference to `no_such_methood()'
clang-5.0: error: linker command failed with exit code 1 (use -v to see
invocation)

--------------------------------------
URL to play with the code: https://godbolt.org/g/1ifDyg

--------------------------------------
#include <new>
#include <cstdlib>

#pragma clang diagnostic ignored "-Winline-new-delete"

 void no_such_methood();
 //void no_such_methood(){asm ("nop");};

inline void* operator new(size_t size) throw(std::bad_alloc)
{
  no_such_methood();
  return malloc(size);
}

inline void* operator new[](size_t size) throw(std::bad_alloc)
{
  no_such_methood();
  return malloc(size);
}

inline void operator delete(void* ptr) throw()
{
  no_such_methood();
  free(ptr);
}

inline void operator delete[](void* ptr) throw()
{
  no_such_methood();
  free(ptr);
}

struct MyStructBase
{
     virtual ~MyStructBase()
     {
  }
};

struct MyStruct : MyStructBase
{
};

int main(void)
{
  MyStruct ss;
  return 0;
} 

--------------------------------------

That is why we use the such code in our project:
https://stackoverflow.com/questions/18365804/is-it-possible-to-completely-disable-the-default-c-new-operator

--------------------------------------
Possibly it compiles in gcc after this change:

http://patchwork.ozlabs.org/patch/604210/

--------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20171204/eb666546/attachment.html>


More information about the llvm-bugs mailing list