Hi Team,

We are using Clang 11 for our product that has common C++ code base for 
Windows, Linux, Macintosh, ….

We observed that sizeof operator gives different value on Windows and 
Linux/OSX, when the inheritance is from a common base class:

Example Sample:

#include <cassert>

struct Base {}; // empty class

struct Derived1 : Base {
    int i;
};

struct Derived2 : Base {
    Base c; // Base, occupies 1 byte, followed by padding for i
    int i;
};

struct Derived3 : Base {
    Derived1 c; // Derived1 is too derived from same Base class
    int i;
};

int main()
{
    assert<http://en.cppreference.com/w/cpp/error/assert>(sizeof(Derived2) == 
2*sizeof(int));

    assert<http://en.cppreference.com/w/cpp/error/assert>(sizeof(Derived3) == 
3*sizeof(int));
}

              When we compile above program using Clang 11 and run it on 
windows and Linux  sizeof(Derived3) give different value.

We don’t want a work-around via making first data member of derived class of 
type different from class that also is derived from same empty base class.
Is there any flag that we can use so that it gives same result on all platform 
(Windows/Linux/OSX/Android/iOS/….)
Or another way to solve this gracefully.

Thank you!

Best Regards,
Vivek

_______________________________________________
cfe-users mailing list
cfe-users@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users

Reply via email to