https://github.com/localspook created https://github.com/llvm/llvm-project/pull/147074
These new traits come from various standard versions: C++14: - `tuple_element_t` C++17: - `is_placeholder_v` - `is_bind_expression_v` - `ratio_equal_v` - `ratio_not_equal_v` - `ratio_less_v` - `ratio_less_equal_v` - `ratio_greater_v` - `ratio_greater_equal_v` - `is_error_code_enum_v` - `is_error_condition_enum_v` - `is_execution_policy_v` - `tuple_size_v` - `variant_size_v` - `uses_allocator_v` - `variant_alternative_t` C++20: - `compare_three_way_result_t` - `common_comparison_category_t` - `unwrap_ref_decay_t` - `unwrap_reference_t` C++23: - `is_implicit_lifetime_v` C++26: - `is_nothrow_relocatable_v` - `is_replaceable_v` - `is_trivially_relocatable_v` - `is_virtual_base_of_v` This doesn't add `treat_as_floating_point_v` or `is_clock_v` because they require more invasive changes; instead I've opened #147072 to track them. >From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin <chernyakin.victo...@outlook.com> Date: Fri, 4 Jul 2025 07:42:54 -0700 Subject: [PATCH] [clang-tidy] Teach `modernize-type-traits` about more type traits --- .../clang-tidy/modernize/TypeTraitsCheck.cpp | 27 +++++++++++++++++++ clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 30 insertions(+) diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp index c0766395ec5cc..92e6f61a6d9d4 100644 --- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp @@ -28,8 +28,10 @@ static const llvm::StringSet<> ValueTraits = { "is_array", "is_assignable", "is_base_of", + "is_bind_expression", "is_bounded_array", "is_class", + "is_clock", "is_compound", "is_const", "is_constructible", @@ -40,10 +42,14 @@ static const llvm::StringSet<> ValueTraits = { "is_destructible", "is_empty", "is_enum", + "is_error_code_enum", + "is_error_condition_enum", + "is_execution_policy", "is_final", "is_floating_point", "is_function", "is_fundamental", + "is_implicit_lifetime", "is_integral", "is_invocable", "is_invocable_r", @@ -65,14 +71,17 @@ static const llvm::StringSet<> ValueTraits = { "is_nothrow_invocable_r", "is_nothrow_move_assignable", "is_nothrow_move_constructible", + "is_nothrow_relocatable", "is_nothrow_swappable", "is_nothrow_swappable_with", "is_null_pointer", "is_object", + "is_placeholder", "is_pointer", "is_pointer_interconvertible_base_of", "is_polymorphic", "is_reference", + "is_replaceable", "is_rvalue_reference", "is_same", "is_scalar", @@ -91,15 +100,27 @@ static const llvm::StringSet<> ValueTraits = { "is_trivially_destructible", "is_trivially_move_assignable", "is_trivially_move_constructible", + "is_trivially_relocatable", "is_unbounded_array", "is_union", "is_unsigned", + "is_virtual_base_of", "is_void", "is_volatile", "negation", "rank", + "ratio_equal", + "ratio_greater_equal", + "ratio_greater", + "ratio_less_equal", + "ratio_less", + "ratio_not_equal", "reference_constructs_from_temporary", "reference_converts_from_temporary", + "treat_as_floating_point", + "tuple_size", + "uses_allocator", + "variant_size", }; static const llvm::StringSet<> TypeTraits = { @@ -130,6 +151,12 @@ static const llvm::StringSet<> TypeTraits = { "result_of", "invoke_result", "type_identity", + "tuple_element", + "variant_alternative", + "compare_three_way_result", + "common_comparison_category", + "unwrap_ref_decay", + "unwrap_reference", }; static DeclarationName getName(const DependentScopeDeclRefExpr &D) { diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index f8f183e9de1cc..3d554733ad3fd 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -276,6 +276,9 @@ Changes in existing checks excluding variables with ``thread_local`` storage class specifier from being matched. +- Improved :doc:`modernize-type-traits + <clang-tidy/checks/modernize/type-traits>` check by detecting more type traits. + - Improved :doc:`modernize-use-default-member-init <clang-tidy/checks/modernize/use-default-member-init>` check by matching arithmetic operations, ``constexpr`` and ``static`` values, and detecting _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits