[llvm-bugs] [Bug 35944] New: incorrect weak-vtables warning on abstract base class

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Jan 13 17:42:04 PST 2018


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

            Bug ID: 35944
           Summary: incorrect weak-vtables warning on abstract base class
           Product: clang
           Version: 5.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: llvm at boxie.eu
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

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?

-- 
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/20180114/32a229f8/attachment.html>


More information about the llvm-bugs mailing list