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: unassignedclangb...@nondot.org
          Reporter: m...@design.ru
                CC: dgre...@apple.com, llvm-bugs@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to