[cfe-dev] VTables in C++98 versus C++11
Robinson, Paul via cfe-dev
cfe-dev at lists.llvm.org
Mon Dec 19 16:12:49 PST 2016
I'm working on making the Clang tests tolerate a default dialect of
C++11 (currently it is C++98). I ran into a funny situation with
test/CodeGenCXX/vtable-layout.cpp, which uses -fdump-vtable-layouts to
look at, well, vtable layouts.
Consider this section of the test:
//////////
namespace Test40 {
struct A {
virtual void foo() = 0;
};
struct B : public A {
virtual void foo();
};
struct C: public B {
virtual int f(int);
virtual int f();
virtual int g(int);
virtual int g();
virtual int h(int);
virtual int h();
virtual int i(int);
virtual int i();
};
class D : C {};
D d;
}
//////////
There is a significant difference in what gets dumped, depending on
the dialect. First let's look at what we get with C++98:
$ clang -cc1 t.cpp -triple=x86_64-apple-darwin10 -emit-llvm-only \
-fdump-vtable-layouts -std=c++98 | grep entries
Vtable for 'Test40::D' (11 entries).
Vtable for 'Test40::C' (11 entries).
VTable indices for 'Test40::C' (8 entries).
Vtable for 'Test40::B' (3 entries).
VTable indices for 'Test40::B' (1 entries).
Vtable for 'Test40::A' (3 entries).
VTable indices for 'Test40::A' (1 entries).
That is, a Vtable for each class, and indices for everything except the
most-derived class.
Now look at what we get with C++11:
$ clang -cc1 t.cpp -triple=x86_64-apple-darwin10 -emit-llvm-only \
-fdump-vtable-layouts -std=c++11 | grep entries
Vtable for 'Test40::D' (11 entries).
That is, all of the base-class information is not present.
Is this a "correct" difference between C++98 and C++11?
If so, then I can just skip this test for the C++11 case.
But it seemed like a pretty weird thing to be different.
Thanks,
--paulr
More information about the cfe-dev
mailing list