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/STLForwardCompat.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/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -44,6 +44,20 @@ struct disjunction : std::conditional>::type {}; +//===----------------------------------------------------------------------===// +// Features from C++20 +//===----------------------------------------------------------------------===// + +template +struct remove_cvref // NOLINT(readability-identifier-naming) +{ + using type = std::remove_cv_t>; +}; + +template +using remove_cvref_t // NOLINT(readability-identifier-naming) + = typename llvm::remove_cvref::type; + } // namespace llvm #endif // LLVM_ADT_STLFORWARDCOMPAT_H diff --git a/llvm/unittests/ADT/STLForwardCompatTest.cpp b/llvm/unittests/ADT/STLForwardCompatTest.cpp --- a/llvm/unittests/ADT/STLForwardCompatTest.cpp +++ b/llvm/unittests/ADT/STLForwardCompatTest.cpp @@ -42,4 +42,37 @@ std::true_type>::value)); } +template +class STLForwardCompatRemoveCVRefTest : public ::testing::Test {}; + +using STLForwardCompatRemoveCVRefTestTypes = ::testing::Types< + // clang-format off + std::pair, + std::pair, + std::pair, + std::pair, + std::pair, + std::pair, + std::pair, + std::pair, + std::pair + // clang-format on + >; + +TYPED_TEST_CASE(STLForwardCompatRemoveCVRefTest, + STLForwardCompatRemoveCVRefTestTypes); + +TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRef) { + using From = typename TypeParam::first_type; + using To = typename TypeParam::second_type; + EXPECT_TRUE( + (std::is_same::type, To>::value)); +} + +TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRefT) { + using From = typename TypeParam::first_type; + EXPECT_TRUE((std::is_same::type, + llvm::remove_cvref_t>::value)); +} + } // namespace