<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 - incorrect weak-vtables warning on abstract base class"
   href="https://bugs.llvm.org/show_bug.cgi?id=35944">35944</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>incorrect weak-vtables warning on abstract base class
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>5.0
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux
          </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>C++
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>llvm@boxie.eu
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following code incorrectly produces a warning:

// compile with -Wweak-vtables
struct foo // warning: 'foo' has no out-of-line virtual method definitions; ...
{
  virtual ~foo() = 0; // abstract dtor to prevent instantiation of foo.

  // eventually other abstract methods...
};

// define dtor to avoid linker error.
foo::~foo() {} // or '= default' with C++11.

Pure abstract base classes (aka interfaces) like foo usually don't declare the
destructor abstract because its definition is needed anyway. However, this has
the drawback that empty interfaces with nothing than a destructor can be
instantiated. The code above does what is not very well known for some reason:
it defines the destructor despite it has previously been declared abstract.

The warning should not be triggered because:
- if foo is being used anywhere it has to have its dtor defined in some
translation unit - in which case the vtable could simply be places there.
- if nobody derives from foo there is no need to emit the vtable in every
translation unit either because... it is not used.

I assume the compiler searches for the first method which is neither abstract
nor inlined and emits the vtable in the translation unit that defines that
method. This could be improved to also accept abstract destructors, which
always have to be defined somewhere.

Am I missing something?</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>