On Mon, May 13, 2013 at 10:04 PM, Timur Iskhodzhanov <span dir="ltr"><<a href="mailto:timurrrr@google.com" target="_blank">timurrrr@google.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"><br>
<br>
================<br>
Comment at: lib/AST/VTableBuilder.cpp:2319<br>
@@ -2318,3 @@<br>
-    //   If a class has an implicitly-defined virtual destructor,<br>
-    //   its entries come after the declared virtual function pointers.<br>
-<br>
----------------<br>
</div><div class="im">Richard Smith wrote:<br>
> Timur Iskhodzhanov wrote:<br>
> > Reid Kleckner wrote:<br>
> > > Timur Iskhodzhanov wrote:<br>
> > > > Reid Kleckner wrote:<br>
> > > > > I don't think Test16::D triggers this case because ~D is overriding ~C, so it goes into the vtable first.<br>
> > > > ><br>
> > > > > When can you have an implicitly defined virtual dtor without overriding the method of a base class?  Is that possible? Good question for Richard or John.<br>
> > > > Err, no.<br>
> > > > There's no ~D in Test16:D.<br>
> > > ><br>
> > > >   struct C : ... { virtual ~C(); };<br>
> > > >   struct D : virtual C {<br>
> > > >     virtual void f();<br>
> > > >   };<br>
> > > ><br>
> > > > So C has virtual ~C, thus D should have a virtual dtor.<br>
> > > > AFAIU, as there's no explicit ~D, there should be an implicit one.<br>
> > > ><br>
> > > > Does that sound right?<br>
> > > Yes, it's implicit, but it wasn't triggering this code, because it should always hit the codepath for overrides and continue the loop before setting ImplicitVirtualDtor.  I'm looking for a counterexample to show that this code isn't dead.<br>

> > Errr, it **was** trigerring this code.<br>
> ><br>
> > I found it by locally replacing the below<br>
> ><br>
> >   if (isMicrosoftABI()) {<br>
> ><br>
> > with<br>
> ><br>
> >   if (1) {<br>
> ><br>
> > and it did report an error on Test16::D<br>
> If any base class of a class X has a virtual destructor, then X also has a virtual destructor, no matter whether it's declared explicitly or implicitly. If no base class of X has a virtual destructor, and X does not declare a destructor, then its implicit destructor is not virtual. Does that answer the question?<br>

</div>Almost, thanks!<br>
<br>
Am I right that if a virtual base class V of a class X has a virtual destructor and X doesn't have an explicitly defined dtor, Sema will put ~X at the end of X `CXXRecordDecl`'s method list (as one can only tell there's no explicit ~X at the end of X's definition)?</blockquote>
<div><br></div><div>It is not guaranteed to be at the end of the method list, and we don't want to provide that guarantee. (As it happens, it often will be at the end, but in practice we could add some implicitly-declared constructors after it.) As for any implicitly-declared special member, we will only add it once we get to the end of parsing the class.</div>
</div>