<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - dllexported dtor and virtual base lead to undefined symbol in debug build"
   href="https://bugs.llvm.org/show_bug.cgi?id=44035">44035</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>dllexported dtor and virtual base lead to undefined symbol in debug build
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>-New Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>oktal3700@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=22829" name="attach_22829" title="repro testcase">attachment 22829</a> <a href="attachment.cgi?id=22829&action=edit" title="repro testcase">[details]</a></span>
repro testcase

When compiling the same code with clang-cl (r375090) and MSVS 2019 (16.3.9),
the LLVM toolchain fails with a linker error, while the Microsoft one does not.

error : undefined symbol: __declspec(dllimport) public: void __thiscall
derived::`vbase dtor'(void)

Full repro below (also in the attachment)

=== lib.h ===
struct base {
    virtual LIBRARY_EXPORT ~base();
};
struct derived : public virtual base {
    virtual LIBRARY_EXPORT ~derived();
};

=== lib.cpp ===
#define LIBRARY_EXPORT __declspec(dllexport)
#include "lib.h"
LIBRARY_EXPORT base::~base() = default;
LIBRARY_EXPORT derived::~derived() = default;

=== main.cpp ===
#define LIBRARY_EXPORT __declspec(dllimport)
#include "lib.h"
int main() {
    derived{};
}

================
LLVM toolchain commands:

<span class="quote">> clang-cl /c /Z7 /W3 /WX- /Od /D _WINDLL /D _MBCS /EHsc /MDd /GS /Gd /TP lib.cpp
> lld-link /OUT:"library.dll" /IMPLIB:"library.lib" /DLL lib.obj
> clang-cl /c /Z7 /W3 /WX- /Od /D _MBCS /EHsc /MDd /GS /Gd /TP main.cpp
> lld-link /OUT:"executable.exe" library.lib main.obj</span >

Output:

lld-link : error : undefined symbol: __declspec(dllimport) public: void
__thiscall derived::`vbase dtor'(void)
<span class="quote">>>> referenced by D:\Mat\Projects\test\executable\main.cpp:5
>>>               Debug\main.obj:(_main)
>>> referenced by D:\Mat\Projects\test\library\lib.h:14
>>>               Debug\main.obj:(public: virtual void * __thiscall derived::`scalar deleting dtor'(unsigned int))</span >

The same commands with the Microsoft toolchain, giving no errors:

<span class="quote">> cl /c /Z7 /W3 /WX- /Od /D _WINDLL /D _MBCS /EHsc /MDd /GS /Gd /TP lib.cpp
> link /OUT:"library.dll" /IMPLIB:"library.lib" /DLL lib.obj
> cl /c /Z7 /W3 /WX- /Od /D _MBCS /EHsc /MDd /GS /Gd /TP main.cpp
> link /OUT:"executable.exe" library.lib main.obj</span >

I've also tried the release binaries of LLVM 8 and 9 and the same issue is
present.</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>