[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:54:44 PDT 2022


bzcheeseman updated this revision to Diff 429377.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D125590/new/

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,14 @@
   }
 };
 
+/// Provides a self-cast that simply returns whatever is given. This doesn't
+/// provide `castFailed` because a cast from T to T should never fail.
+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) doCastIfPossible(const T &t) { return t; }
+};
+
 //===----------------------------------------------------------------------===//
 // Pre-specialized CastInfo
 //===----------------------------------------------------------------------===//


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


More information about the llvm-commits mailing list