From 4ab89d8bbbe3d8d64c2501840796f4bef133b0db Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 26 Mar 2025 21:42:05 -0600 Subject: [PATCH] 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. --- AK/Swift.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/AK/Swift.h b/AK/Swift.h index 4f9855b0783..053ec38be66 100644 --- a/AK/Swift.h +++ b/AK/Swift.h @@ -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 +To cxxCast(From i) +{ + return static_cast(i); +}