https://github.com/kparzysz updated https://github.com/llvm/llvm-project/pull/146390
>From 7c294619f38984e26264d25524f6f5e79397f297 Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Mon, 30 Jun 2025 11:45:43 -0500 Subject: [PATCH 1/3] [STLForwardCompat] Implement llvm::type_identity, NFC --- .../include/clang/Tooling/Transformer/Transformer.h | 13 ++++--------- llvm/include/llvm/ADT/STLForwardCompat.h | 10 ++++++++++ 2 files changed, 14 insertions(+), 9 deletions(-) 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 <class T> struct type_identity { - using type = T; -}; } // namespace detail template <typename T> struct TransformerResult { @@ -95,8 +90,8 @@ class Transformer : public ast_matchers::MatchFinder::MatchCallback { template <typename MetadataT> explicit Transformer( transformer::RewriteRuleWith<MetadataT> Rule, - std::function<void(llvm::Expected<TransformerResult< - typename detail::type_identity<MetadataT>::type>>)> + std::function<void( + llvm::Expected<TransformerResult<llvm::type_identity_t<MetadataT>>>)> Consumer); /// N.B. Passes `this` pointer to `MatchFinder`. So, this object should not @@ -200,8 +195,8 @@ template <typename T> class WithMetadataImpl final : public TransformerImpl { template <typename MetadataT> Transformer::Transformer( transformer::RewriteRuleWith<MetadataT> Rule, - std::function<void(llvm::Expected<TransformerResult< - typename detail::type_identity<MetadataT>::type>>)> + std::function<void( + llvm::Expected<TransformerResult<llvm::type_identity_t<MetadataT>>>)> Consumer) : Impl(std::make_unique<detail::WithMetadataImpl<MetadataT>>( std::move(Rule), std::move(Consumer))) {} diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index 75a0d4acf67f1..370caf5a897b5 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -36,6 +36,16 @@ template <typename T> using remove_cvref_t // NOLINT(readability-identifier-naming) = typename llvm::remove_cvref<T>::type; +template <typename T> +struct type_identity // NOLINT(readability-identifier-naming) +{ + using type = T; +}; + +template <typename T> +using type_identity_t // NOLINT(readability-identifier-naming) + = typename llvm::type_identity<T>::type; + //===----------------------------------------------------------------------===// // Features from C++23 //===----------------------------------------------------------------------===// >From e381f6018dcfff5ea0944dedcf9dc4d34103ee6f Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Mon, 30 Jun 2025 12:53:43 -0500 Subject: [PATCH 2/3] Add TODO --- llvm/include/llvm/ADT/STLForwardCompat.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/llvm/include/llvm/ADT/STLForwardCompat.h b/llvm/include/llvm/ADT/STLForwardCompat.h index 370caf5a897b5..7bd2c8705f393 100644 --- a/llvm/include/llvm/ADT/STLForwardCompat.h +++ b/llvm/include/llvm/ADT/STLForwardCompat.h @@ -36,12 +36,15 @@ template <typename T> using remove_cvref_t // NOLINT(readability-identifier-naming) = typename llvm::remove_cvref<T>::type; +// TODO: Remove this in favor of std::type_identity<T> once we switch to C++23. template <typename T> struct type_identity // NOLINT(readability-identifier-naming) { using type = T; }; +// TODO: Remove this in favor of std::type_identity_t<T> once we switch to +// C++23. template <typename T> using type_identity_t // NOLINT(readability-identifier-naming) = typename llvm::type_identity<T>::type; >From 0df08400b934db1f2cdfcc0af310c11efc57a3be Mon Sep 17 00:00:00 2001 From: Krzysztof Parzyszek <krzysztof.parzys...@amd.com> Date: Mon, 30 Jun 2025 14:16:31 -0500 Subject: [PATCH 3/3] Add unit test --- llvm/unittests/ADT/STLForwardCompatTest.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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<From>>::value)); } +template <typename T> class TypeIdentityTest : public ::testing::Test { +public: + using TypeIdentity = llvm::type_identity<T>; +}; + +struct A { + struct B {}; +}; +using TypeIdentityTestTypes = + ::testing::Types<int, volatile int, A, const A::B>; + +TYPED_TEST_SUITE(TypeIdentityTest, TypeIdentityTestTypes, /*NameGenerator*/); + +TYPED_TEST(TypeIdentityTest, Identity) { + // TestFixture is the instantiated TypeIdentityTest. + EXPECT_TRUE( + (std::is_same_v<TypeParam, typename TestFixture::TypeIdentity::type>)); +} + TEST(TransformTest, TransformStd) { std::optional<int> A; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits