diff --git a/llvm/include/llvm/ADT/Any.h b/llvm/include/llvm/ADT/Any.h --- a/llvm/include/llvm/ADT/Any.h +++ b/llvm/include/llvm/ADT/Any.h @@ -114,27 +114,23 @@ template bool any_isa(const Any &Value) { if (!Value.Storage) return false; - return Value.Storage->id() == - &Any::TypeId>>::Id; + return Value.Storage->id() == &Any::TypeId>::Id; } template T any_cast(const Any &Value) { - return static_cast( - *any_cast>>(&Value)); + return static_cast(*any_cast>(&Value)); } template T any_cast(Any &Value) { - return static_cast( - *any_cast>>(&Value)); + return static_cast(*any_cast>(&Value)); } template T any_cast(Any &&Value) { - return static_cast(std::move( - *any_cast>>(&Value))); + return static_cast(std::move(*any_cast>(&Value))); } template const T *any_cast(const Any *Value) { - using U = std::remove_cv_t>; + using U = remove_cvref_t; assert(Value && any_isa(*Value) && "Bad any cast!"); if (!Value || !any_isa(*Value)) return nullptr; diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -34,6 +34,7 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/STLShims.h" #include "llvm/Support/MemAlloc.h" #include "llvm/Support/type_traits.h" #include @@ -60,8 +61,8 @@ std::enable_if_t::value && std::is_trivially_destructible::value>; template -using EnableUnlessSameType = std::enable_if_t>, ThisT>::value>; +using EnableUnlessSameType = + std::enable_if_t, ThisT>::value>; template using EnableIfCallable = std::enable_if_t::value || diff --git a/llvm/include/llvm/ADT/STLExtras.h b/llvm/include/llvm/ADT/STLExtras.h --- a/llvm/include/llvm/ADT/STLExtras.h +++ b/llvm/include/llvm/ADT/STLExtras.h @@ -186,9 +186,8 @@ function_ref( Callable &&callable, // This is not the copy-constructor. - std::enable_if_t< - !std::is_same>, - function_ref>::value> * = nullptr, + std::enable_if_t, + function_ref>::value> * = nullptr, // Functor must be callable and return a suitable type. std::enable_if_t::value || std::is_convertible()( diff --git a/llvm/include/llvm/ADT/STLShims.h b/llvm/include/llvm/ADT/STLShims.h --- a/llvm/include/llvm/ADT/STLShims.h +++ b/llvm/include/llvm/ADT/STLShims.h @@ -42,6 +42,17 @@ struct disjunction : std::conditional>::type {}; +//===----------------------------------------------------------------------===// +// Shims for C++20 +//===----------------------------------------------------------------------===// + +template struct SHIM(remove_cvref) { + using type = std::remove_cv_t>; +}; + +template +using SHIM(remove_cvref_t) = typename llvm::remove_cvref::type; + } // namespace llvm #endif // LLVM_ADT_STLSHIMS_H diff --git a/llvm/unittests/ADT/STLShimsTest.cpp b/llvm/unittests/ADT/STLShimsTest.cpp --- a/llvm/unittests/ADT/STLShimsTest.cpp +++ b/llvm/unittests/ADT/STLShimsTest.cpp @@ -42,4 +42,21 @@ std::true_type>::value)); } +TEST(STLShims, RemoveCVRef) { +#define REMOVE_CVREF_CASE(FROM, TO) \ + EXPECT_TRUE((std::is_same::type, \ + llvm::remove_cvref_t>::value)); \ + EXPECT_TRUE((std::is_same, TO>::value)); + REMOVE_CVREF_CASE(int, int); + REMOVE_CVREF_CASE(int &, int); + REMOVE_CVREF_CASE(const int, int); + REMOVE_CVREF_CASE(volatile int, int); + REMOVE_CVREF_CASE(const volatile int &, int); + REMOVE_CVREF_CASE(int *, int *); + REMOVE_CVREF_CASE(int *const, int *); + REMOVE_CVREF_CASE(const int *, const int *); + REMOVE_CVREF_CASE(int *&, int *); +#undef REMOVE_CVREF_CASE +} + } // namespace