<div dir="ltr">I think the difference here is that D's implicit default constructor becomes constexpr by default in C++11, so there's no dynamic initialization.<div><br></div><div>In C++98, we would have a dynamic initializer that calls D::D(), which would call C::C(), and so on, referencing all vtables as we go. In C++11, we can statically initialize 'd' without calling C::C(), and without referencing C's vtable at all.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Dec 20, 2016 at 10:48 AM, Robinson, Paul via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
<br>
> -----Original Message-----<br>
> From: cfe-dev [mailto:<a href="mailto:cfe-dev-bounces@lists.llvm.org">cfe-dev-bounces@lists.<wbr>llvm.org</a>] On Behalf Of<br>
> Robinson, Paul via cfe-dev<br>
> Sent: Monday, December 19, 2016 4:13 PM<br>
> To: <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
> Subject: [cfe-dev] VTables in C++98 versus C++11<br>
><br>
> I'm working on making the Clang tests tolerate a default dialect of<br>
> C++11 (currently it is C++98). I ran into a funny situation with<br>
> test/CodeGenCXX/vtable-layout.<wbr>cpp, which uses -fdump-vtable-layouts to<br>
> look at, well, vtable layouts.<br>
><br>
> Consider this section of the test:<br>
> //////////<br>
> namespace Test40 {<br>
> struct A {<br>
> virtual void foo() = 0;<br>
> };<br>
> struct B : public A {<br>
> virtual void foo();<br>
> };<br>
> struct C: public B {<br>
> virtual int f(int);<br>
> virtual int f();<br>
> virtual int g(int);<br>
> virtual int g();<br>
> virtual int h(int);<br>
> virtual int h();<br>
> virtual int i(int);<br>
> virtual int i();<br>
> };<br>
> class D : C {};<br>
> D d;<br>
> }<br>
> //////////<br>
><br>
> There is a significant difference in what gets dumped, depending on<br>
> the dialect. First let's look at what we get with C++98:<br>
><br>
> $ clang -cc1 t.cpp -triple=x86_64-apple-darwin10 -emit-llvm-only \<br>
> -fdump-vtable-layouts -std=c++98 | grep entries<br>
> Vtable for 'Test40::D' (11 entries).<br>
> Vtable for 'Test40::C' (11 entries).<br>
> VTable indices for 'Test40::C' (8 entries).<br>
> Vtable for 'Test40::B' (3 entries).<br>
> VTable indices for 'Test40::B' (1 entries).<br>
> Vtable for 'Test40::A' (3 entries).<br>
> VTable indices for 'Test40::A' (1 entries).<br>
><br>
> That is, a Vtable for each class, and indices for everything except the<br>
> most-derived class.<br>
><br>
> Now look at what we get with C++11:<br>
><br>
> $ clang -cc1 t.cpp -triple=x86_64-apple-darwin10 -emit-llvm-only \<br>
> -fdump-vtable-layouts -std=c++11 | grep entries<br>
> Vtable for 'Test40::D' (11 entries).<br>
><br>
> That is, all of the base-class information is not present.<br>
><br>
> Is this a "correct" difference between C++98 and C++11?<br>
> If so, then I can just skip this test for the C++11 case.<br>
> But it seemed like a pretty weird thing to be different.<br>
<br>
</div></div>If I define one of C's virtual functions, then we emit the<br>
vtable as expected for C++11 too. I guess I'll go with that.<br>
<div class="HOEnZb"><div class="h5"><br>
><br>
> Thanks,<br>
> --paulr<br>
><br>
> ______________________________<wbr>_________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</div></div></blockquote></div><br></div>