Check for multiple inheritance of the base classes too

If C++ wrappers for a class are not generated because it uses multiple
inheritance, we can't generate the C++ wrappers for any classes deriving
from it neither, so don't do it.

This fixes failure in multiple_inheritance_overload unit test.
This commit is contained in:
Vadim Zeitlin 2022-09-17 15:08:31 +02:00
commit 523e58aa06

View file

@ -968,6 +968,39 @@ private:
};
/*
Return true if the class, or one of its base classes, uses multiple inheritance, i.e. has more than one base class.
The output first_base parameter is optional and is filled with the first base class (if any).
*/
bool uses_multiple_inheritance(Node* n, scoped_dohptr* first_base_out = NULL) {
if (first_base_out)
first_base_out->reset();
List* const baselist = Getattr(n, "bases");
if (!baselist)
return false;
scoped_dohptr first_base;
for (Iterator i = First(baselist); i.item; i = Next(i)) {
if (Checkattr(i.item, "feature:ignore", "1"))
continue;
if (first_base)
return true;
if (uses_multiple_inheritance(i.item))
return true;
first_base = Copy(i.item);
}
if (first_base_out)
*first_base_out = first_base;
return false;
}
/*
cxx_class_wrapper
@ -991,28 +1024,19 @@ public:
String* const classname = Getattr(n, "sym:name");
scoped_dohptr base_classes(NewStringEmpty());
if (List *baselist = Getattr(n, "bases")) {
for (Iterator i = First(baselist); i.item; i = Next(i)) {
if (Checkattr(i.item, "feature:ignore", "1"))
continue;
if (uses_multiple_inheritance(n, &first_base_)) {
Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n),
"Multiple inheritance not supported yet, skipping C++ wrapper generation for %s\n",
classname
);
if (first_base_) {
Swig_warning(WARN_C_UNSUPPORTTED, Getfile(n), Getline(n),
"Multiple inheritance not supported yet, skipping C++ wrapper generation for %s\n",
classname
);
// Return before initializing class_node_, so that the dtor won't output anything neither.
return;
}
first_base_ = Copy(i.item);
}
if (first_base_)
Printv(base_classes, " : public ", Getattr(first_base_, "sym:name"), NIL);
// Return before initializing class_node_, so that the dtor won't output anything neither.
return;
}
if (first_base_)
Printv(base_classes, " : public ", Getattr(first_base_, "sym:name"), NIL);
Printv(cxx_wrappers_.sect_types,
"class ", classname, ";\n",
NIL