I have a C++ application using multiple inheritance and polymorphism. It works correctly on x86_64-linux but on arm-linux I'm experiencing a segmentation fault.
I've written a simple test to re-create the problem:
#include <list>
#include <iostream>
class SmartObject
{
public:
// removing this destructor makes it work in ANY way
virtual ~SmartObject(){
}
void method(void) {}
};
class IMyInterface
{
public:
// removing this destructor have no effect (fails)
virtual ~IMyInterface(){
}
virtual std::list<int> getList() = 0;
};
class MyObject : public SmartObject, public virtual IMyInterface
{
public:
MyObject()
{
list.push_back(4);
list.push_back(5);
}
virtual std::list<int> getList() {
return list;
}
std::list<int> list;
};
int main()
{
IMyInterface * ip = new MyObject();
std::list<int> list_clone = ip->getList();
std::cout << list_clone.size() << std::endl;
delete ip;
return 0;
}
This code works correctly on x64-linux and win32 (also on other embedded platforms) but on arm-linux it causes a segmentation fault when calling list_clone.size() because the copied list have an incorrect tail pointer.
I have tried with gcc 4.8.3 and 4.9.1 but I've seen the same behavior. The target architecture is ARM cortex-A processors with hard floating point.
Any idea?
Actually I have find two independent ways to make it work:
class MyObject : public virtual IMyInterface, public virtual SmartObject
Thanks in advance
It's a bug of gcc 4.9.X on ARM targets. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66666-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With