Update needed to binary compatibility guide for Windows?
Nicolás Alvarez
nicolas.alvarez at gmail.com
Mon Apr 14 03:15:30 BST 2014
2014-04-13 22:36 GMT-03:00 Michael Pyne <mpyne at kde.org>:
> Hi all,
>
> In the past couple of days our Binary Compatibility in C++ TechBase page [1]
> was posted to Reddit [2].
>
> That post received a response [3] which indicated that we're actually missed a
> potential source of binary incompatibility with virtual functions on Windows
> with MSVC.
>
> Specifically, that adding an override of an existing virtual function in a
> class may cause other vtable function entries to be re-ordered. E.g. in
> something like:
>
> class blah
> {
> public:
> virtual void func1(int arg);
> virtual void func2(int arg);
> virtual void func3(int arg);
> };
>
> Adding a virtual override "func2(char *arg)" to the *end* might cause the
> vftable to line up as if declared in this order:
>
> class blah
> {
> public:
> virtual void func1(int arg);
> virtual void func2(int arg);
> virtual void func2(char *arg);
> virtual void func3(int arg); // moved
> };
>
> Is anyone able to confirm this behavior on Windows? If it's true, do we want
> to adopt a constraint on our handling of virtual functions in leaf classes
> based on this? (Adding virtual methods is already not permitted for non-leaf
> classes)
I can confirm this behavior happens.
I compiled this class:
struct Testobj {
virtual void func1();
virtual void func2();
virtual void func3();
};
And a program that calls func1(); func2(); func3();
Then I added a func2(int) overload to the *end*:
struct Testobj {
virtual void func1();
virtual void func2();
virtual void func3();
virtual void func2(int);
};
and recompiled the class but not the program using the class.
Output of calling func1(); func2(); func3(); was
This is func1
This is func2 taking int
This is func2
This shows that if I declare func1() func2() func3() func2(int), the
vtable is laid out as func1() func2(int) func2() func3().
Tested with MSVC2010.
--
Nicolás
More information about the kde-core-devel
mailing list