[llvm] [Support] Extend ExtensibleRTTI utility to support basic multiple inheritance. (PR #112643)
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 17 10:02:18 PDT 2024
================
@@ -110,21 +106,36 @@ class RTTIRoot {
/// static char ID;
/// };
///
-template <typename ThisT, typename ParentT>
-class RTTIExtends : public ParentT {
+template <typename ThisT, typename... ParentTs>
+class RTTIExtends : public ParentTs... {
public:
// Inherit constructors from ParentT.
- using ParentT::ParentT;
+ using ParentTs::ParentTs...;
static const void *classID() { return &ThisT::ID; }
const void *dynamicClassID() const override { return &ThisT::ID; }
+ /// Check whether this instance is a subclass of QueryT.
+ template <typename QueryT> bool isA() const { return isA(QueryT::classID()); }
+
bool isA(const void *const ClassID) const override {
- return ClassID == classID() || ParentT::isA(ClassID);
+ return ClassID == classID() || parentsAreA<ParentTs...>(ClassID);
----------------
dwblaikie wrote:
Might be able to skip the `parentsAreA` helper:
```
return ClassId == classId() || (ParentTs::isA(ClassID) || ...);
```
(here's at least a little proof of concept I did: https://godbolt.org/z/vGca7jYbT )
https://github.com/llvm/llvm-project/pull/112643
More information about the llvm-commits
mailing list