AK: Add cxxCast template to allow Swift to perform simple checked casts

This is a workaround for the lack of support for imported class
hierarchies in Swift. Swift's ClangImporter doesn't tell the Swift
frontend about derived class relationships between imported types.
This commit is contained in:
Andrew Kaster 2025-03-26 21:42:05 -06:00 committed by Andrew Kaster
parent e4c88915ab
commit 4ab89d8bbb
Notes: github-actions[bot] 2025-04-03 22:49:33 +00:00

View file

@ -37,3 +37,11 @@
# define SWIFT_RETURNS_RETAINED
# define SWIFT_RETURNS_UNRETAINED
#endif
// FIXME: This needs to be in the global namespace for reasons
// https://github.com/swiftlang/swift/issues/80231
template<class From, class To>
To cxxCast(From i)
{
return static_cast<To>(i);
}