[PATCH] D125576: [LLVM][Casting.h] Add ForwardToPointerCast trait
Aman LaChapelle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 15:49:07 PDT 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc7587080188e: [LLVM][Casting.h] Add ForwardToPointerCast trait (authored by bzcheeseman).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125576/new/
https://reviews.llvm.org/D125576
Files:
llvm/include/llvm/Support/Casting.h
Index: llvm/include/llvm/Support/Casting.h
===================================================================
--- llvm/include/llvm/Support/Casting.h
+++ llvm/include/llvm/Support/Casting.h
@@ -408,6 +408,29 @@
}
};
+/// Provides a cast trait that uses a defined pointer to pointer cast as a base
+/// for reference-to-reference casts. Note that it does not provide castFailed
+/// and doCastIfPossible because a pointer-to-pointer cast would likely just
+/// return `nullptr` which could cause nullptr dereference. You can use it like
+/// this:
+///
+/// template <> struct CastInfo<foo, bar *> { ... verbose implementation... };
+///
+/// template <>
+/// struct CastInfo<foo, bar>
+/// : public ForwardToPointerCast<foo, bar, CastInfo<foo, bar *>> {};
+///
+template <typename To, typename From, typename ForwardTo>
+struct ForwardToPointerCast {
+ static inline bool isPossible(const From &f) {
+ return ForwardTo::isPossible(&f);
+ }
+
+ static inline decltype(auto) doCast(const From &f) {
+ return *ForwardTo::doCast(&f);
+ }
+};
+
//===----------------------------------------------------------------------===//
// CastInfo
//===----------------------------------------------------------------------===//
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125576.429374.patch
Type: text/x-patch
Size: 1246 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/424bf668/attachment.bin>
More information about the llvm-commits
mailing list