diff --git a/clang/include/clang/Tooling/Transformer/Transformer.h b/clang/include/clang/Tooling/Transformer/Transformer.h index 71b1fe81b9518..ecf7c0912d2d8 100644 --- a/clang/include/clang/Tooling/Transformer/Transformer.h +++ b/clang/include/clang/Tooling/Transformer/Transformer.h @@ -42,11 +42,6 @@ class TransformerImpl { virtual void onMatchImpl(const ast_matchers::MatchFinder::MatchResult &Result) = 0; }; - -// FIXME: Use std::type_identity or backport when available. -template struct type_identity { - using type = T; -}; } // namespace detail template struct TransformerResult { @@ -95,8 +90,8 @@ class Transformer : public ast_matchers::MatchFinder::MatchCallback { template explicit Transformer( transformer::RewriteRuleWith Rule, - std::function::type>>)> + std::function>>)> Consumer); /// N.B. Passes `this` pointer to `MatchFinder`. So, this object should not @@ -200,8 +195,8 @@ template class WithMetadataImpl final : public TransformerImpl { template Transformer::Transformer( transformer::RewriteRuleWith Rule, - std::function::type>>)> + std::function>>)> Consumer) : Impl(std::make_unique>( std::move(Rule), std::move(Consumer))) {} diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index 75a0d4acf67f1..7bd2c8705f393 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -36,6 +36,19 @@ template using remove_cvref_t // NOLINT(readability-identifier-naming) = typename llvm::remove_cvref::type; +// TODO: Remove this in favor of std::type_identity once we switch to C++23. +template +struct type_identity // NOLINT(readability-identifier-naming) +{ + using type = T; +}; + +// TODO: Remove this in favor of std::type_identity_t once we switch to +// C++23. +template +using type_identity_t // NOLINT(readability-identifier-naming) + = typename llvm::type_identity::type; + //===----------------------------------------------------------------------===// // Features from C++23 //===----------------------------------------------------------------------===// diff --git a/llvm/unittests/ADT/STLForwardCompatTest.cpp b/llvm/unittests/ADT/STLForwardCompatTest.cpp index b856386aa3e45..e3d500aa7b55a 100644 --- a/llvm/unittests/ADT/STLForwardCompatTest.cpp +++ b/llvm/unittests/ADT/STLForwardCompatTest.cpp @@ -45,6 +45,25 @@ TYPED_TEST(STLForwardCompatRemoveCVRefTest, RemoveCVRefT) { llvm::remove_cvref_t>::value)); } +template class TypeIdentityTest : public ::testing::Test { +public: + using TypeIdentity = llvm::type_identity; +}; + +struct A { + struct B {}; +}; +using TypeIdentityTestTypes = + ::testing::Types; + +TYPED_TEST_SUITE(TypeIdentityTest, TypeIdentityTestTypes, /*NameGenerator*/); + +TYPED_TEST(TypeIdentityTest, Identity) { + // TestFixture is the instantiated TypeIdentityTest. + EXPECT_TRUE( + (std::is_same_v)); +} + TEST(TransformTest, TransformStd) { std::optional A;