[PATCH] D125590: [LLVM][Casting.h] Add trivial self-cast

Aman LaChapelle via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 13 15:50:44 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.

Casting from a type to itself should always be possible. Make this simple for all users. Ref: https://reviews.llvm.org/D125543


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125590

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
@@ -525,6 +525,13 @@
   }
 };
 
+template <typename T> struct CastInfo<T, T> {
+  static bool isPossible(const T &t) { return true; }
+  static decltype(auto) doCast(const T &t) { return t; }
+  static decltype(auto) castFailed() { return T(nullptr); }
+  static decltype(auto) doCastIfPossible(const T &t) { return t; }
+};
+
 //===----------------------------------------------------------------------===//
 // Pre-specialized CastInfo
 //===----------------------------------------------------------------------===//


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125590.429376.patch
Type: text/x-patch
Size: 711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220513/238db160/attachment.bin>


More information about the llvm-commits mailing list