title: What is the meaning of clang's -Wweak-vtables?
body: <p>I basically do not understand clang's <code>-Wweak-vtables</code>. Here is what I observed so far:</p>
  
  <p><strong>Case one:</strong> (triggers the warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}        
  };
  
  class B : public A {
      public:
      virtual ~B(){}
  };
  
  int main(){}
  </code></pre>
  
  <p><strong>Case two:</strong> (Does not trigger warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}        
  };   
  
  int main(){}
  </code></pre>
  
  <p><strong>Case three:</strong> (Does not trigger warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A();
  
  };
  
  A::~A(){}
  
  class B : public A {
      public:
      virtual ~B(){}
  };
  
  int main(){}
  </code></pre>
  
  <p><strong>Case four:</strong> (Triggers warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}
      virtual void fun(){}        
  };    
  
  class B : public A {
      public:
      virtual ~B(){}
  };
  
  int main(){}
  </code></pre>
  
  <p><strong>Case five:</strong> (Does not trigger warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}
      virtual void fun();      
  };    
  
  class B : public A {
      public:
      virtual ~B(){}
  };
  
  int main(){}
  </code></pre>
  
  <p><strong>Case six:</strong> (Does not trigger warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}
      virtual void fun(){}
  };    
  
  class B : public A {};
  
  int main(){}
  </code></pre>
  
  <p><strong>Case seven:</strong> (Does not trigger warning)</p>
  
  <pre><code>class A {
      public:
      virtual ~A(){}
      virtual void fun(){}
  };    
  
  class B : public A {
      public:
      virtual void fun(){}
  };
  
  int main(){}
  </code></pre>
  
  <p>The exact warning is</p>
  
  <pre><code>warning: 'A' has no out-of-line virtual method definitions; its vtable 
  will be emitted in every translation unit [-Wweak-vtables]
  </code></pre>
  
  <p>So apparently, if I do not declare a non-inline virtual function in a class, it causes some
  kind of problem if and only if I derive from it and the derived class has a virtual destructor.</p>
  
  <p><strong>Questions:</strong></p>
  
  <ol>
  <li>Why is this a problem?</li>
  <li>Why does this get fixed by declaring a virtual function? (Warning speaks of 
  definitions)</li>
  <li>Why does the warning not occur when I do not derive from the class?</li>
  <li>Why does the warning not occur when the derived class does not have a virtual destructor?</li>
  </ol>