[PATCH] D125578: [LLVM][Casting.h] Remove CastInfo pointer partial specialization.
Aman LaChapelle via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 12:57:46 PDT 2022
bzcheeseman created this revision.
Herald added a project: All.
bzcheeseman requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Since cast_convert_val now has pointer specializations, we don't need the pointer partial specialization for CastInfo. We want to trim these down when possible to avoid future ambiguous partial specialization errors.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D125578
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
@@ -479,47 +479,18 @@
using CastReturnType = typename cast_retty<To, From>::ret_type;
- static inline CastReturnType doCast(From &f) {
- return cast_convert_val<To, From,
- typename simplify_type<From>::SimpleType>::doit(f);
+ static inline CastReturnType doCast(const From &f) {
+ return cast_convert_val<
+ To, From,
+ typename simplify_type<From>::SimpleType>::doit(const_cast<From &>(f));
}
// This assumes that you can construct the cast return type from `nullptr`.
// This is largely to support legacy use cases - if you don't want this
// behavior you should specialize CastInfo for your use case.
- //
- // FIXME: fix legacy use cases to specialize CastInfo so we can remove these
- // two - they don't really belong here, as it doesn't make sense to
- // have a fallible reference-to-reference cast if the type isn't
- // constructible from nullptr, which doesn't really happen in LLVM
- // outside of MLIR (which is a separate use case in itself).
static inline CastReturnType castFailed() { return CastReturnType(nullptr); }
- static inline CastReturnType doCastIfPossible(From &f) {
- if (!Self::isPossible(f))
- return castFailed();
- return doCast(f);
- }
-};
-
-/// Provides a CastInfo partial specialization for pointers. This version *does*
-/// provide castFailed and doCastIfPossible because for pointers, a fallible
-/// cast is trivial - just return nullptr.
-template <typename To, typename From>
-struct CastInfo<To, From *, std::enable_if_t<is_simple_type<From>::value>>
- : public CastIsPossible<To, From *> {
- using Self = CastInfo<To, From *>;
-
- using CastReturnType = typename cast_retty<To, From *>::ret_type;
-
- static inline CastReturnType doCast(From *f) {
- // We know it is a simple type, so we can just do cast_convert_val.
- return cast_convert_val<To, From *, From *>::doit(f);
- }
-
- static inline CastReturnType castFailed() { return CastReturnType(nullptr); }
-
- static inline CastReturnType doCastIfPossible(From *f) {
+ static inline CastReturnType doCastIfPossible(const From &f) {
if (!Self::isPossible(f))
return castFailed();
return doCast(f);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125578.429332.patch
Type: text/x-patch
Size: 2442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/f3ddf35d/attachment.bin>
More information about the llvm-commits
mailing list