mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
It is possible for a C++ class template to inherit from a specialization of itself. Normally, these are imported to Swift as separate (unrelated) types, but when symbolic import is enabled, unspecialized templates are imported in place of their specializations, leading to circularly inheriting classes to seemingly inherit from themselves. This patch adds a check to guard against the most common case of circular inheritance, when a class template directly inherits from itself. This pattern appears in a recent version of libc++, necessitating this patch. However, the solution here is imperfect as it does not handle more complex/contrived circular inheritance patterns. This patch also adds a test case exercising this pattern. The -index-store-path flag causes swift-frontend to index the C++ module with symbolic import enabled, without the fix in this patch, that test triggers an assertion failure due to the circular reference (and can infinitely recurse in the StorageVisitor when assertions are disabled). rdar://148026461
33 lines
583 B
C++
33 lines
583 B
C++
#ifndef CIRCULAR_INHERITANCE_H
|
|
#define CIRCULAR_INHERITANCE_H
|
|
|
|
struct DinoEgg {
|
|
void dinoEgg(void) const {}
|
|
};
|
|
|
|
template <typename Chicken>
|
|
struct Egg;
|
|
|
|
template <>
|
|
struct Egg<void> : DinoEgg {
|
|
Egg() {}
|
|
void voidEgg(void) const {}
|
|
};
|
|
|
|
template <typename Chicken>
|
|
struct Egg : Egg<void> {
|
|
Egg(Chicken _chicken) {}
|
|
Chicken chickenEgg(Chicken c) const { return c; }
|
|
};
|
|
|
|
typedef Egg<void> VoidEgg;
|
|
typedef Egg<bool> BoolEgg;
|
|
typedef Egg<Egg<void>> EggEgg;
|
|
|
|
struct NewEgg : Egg<int> {
|
|
NewEgg() : Egg<int>(555) {}
|
|
void newEgg() const {}
|
|
};
|
|
|
|
#endif // !CIRCULAR_INHERITANCE_H
|