Crash in vector of nested classes
Sorry I can't provide too many details about this one. We have a case where two nested classes of the same name, both inheriting from a common base, will crash if a user accesses a vector of one of these nested classes. If you take out the inheritance it won't crash and if you structure the nesting differently it seems like it won't crash either.
I'm using:
cppyy 2.4.0 py38h2a8c4cf_0 conda-forge
cppyy-backend 1.14.9 py38h43d8883_0 conda-forge
cppyy-cling 6.27.0 py38h8225899_0 conda-forge
cpycppyy 1.12.11 py38h43d8883_0 conda-forge
and here's the test script:
import cppyy
cppyy.cppdef('''
#include <vector>
namespace Test {
struct Common { std::string name; };
struct Family1 {
struct Parent : Common {
struct Child : Common { };
std::vector<Child> children;
};
};
struct Family2 {
struct Parent : Common {
struct Child : Common { };
std::vector<Child> children;
};
};
} // namespace Test
''')
from cppyy.gbl import Test
p = Test.Family1.Parent()
p.children
This particular script will crash on exit, though we have a case where simply accessing the vector will cause a crash. Any help would be appreciated. Thanks for the good work!
Looks like somewhere deep inside of Cling (or even Clang, to be honest) an assumption of a virtual dtor existing is being made, but Common does not have one.
I'll see whether this is worth intercepting in the dtor call in the backend, otherwise it will have to be upstreamed, which always takes (much) longer.
Ran into this same virtual dtor crash issue while trying to update from an older cppyy (version 1.9.5)
Is there any update regarding this issue? mostly if we'll need to wait for the upstream fix
you can once try this in replit where all new version avilable
the output error of the issued snippet above is as follow
{}
*** Break *** segmentation violation
*** Break *** segmentation violation
actually, the simpler version as bellow causes the same error as well
import cppyy
cppyy.cppdef('''
#include <string>
#include <vector>
struct Common {
std::string name;
};
struct Parent : Common {
// ~Parent() {}
// using Common::name;
std::vector<Common> children;
};
''')
p = cppyy.gbl.Parent()
print(p.children)
The error can be resolved if u uncomment the destructor for Parent(). It also can work if u change struct to class.
Thus, the issue is not relating to the nested or same-name definition. Somehow, when both Parent and its member inherits from the same base Common, the compiler cannot destruct the resource properly.