[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
github-actions[bot] wrote: @localspook Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor closed https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
localspook wrote: When we're ready to merge, someone please do it for me, I don't have write permissions. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor approved this pull request. LGTM, we'd wait a couple of days before merge in case someone else wants to review it too. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook updated
https://github.com/llvm/llvm-project/pull/147074
>From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:42:54 -0700
Subject: [PATCH 1/6] [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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
>From 930db523cdbe6bf44b334a17667229e3586981aa Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:59:02 -0700
Subject: [PATCH 2/6] Whoops, didn't exclude `treat_as_floating_point_v` or
`is_clock_v`
---
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 92e6f61a6d9d4..aaf9d08c63b2e 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -31,7 +31,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_bind_expression",
"is_bounded_array",
"is_class",
-"is_clock",
"is_compound",
"is_const",
"is_constructible",
@@ -117,7 +116,6 @@ static const llvm::StringSet<> ValueTraits = {
"ratio_not_equal",
"reference_constructs_from_temporary",
"reference_converts_from_temporary",
-"treat_as_floating_point",
"tuple_size",
"uses_allocator",
"variant_size",
>From 13dcaabd66610972db0e6e52e49bb63878e248a6 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 08:15:53 -0700
Subject: [PATCH 3/6] clang-format
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +155,10 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"compare_three_way_result",
+"common_comparison_category",
localspook wrote:
> We usually don't care if there would be a warning inside system headers, we
> only check user-code. It's okay if internal implementation would give a
> warning - it is usually filtered out.
Ah, that's what I was missing!
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +155,10 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"compare_three_way_result",
+"common_comparison_category",
vbvictor wrote:
We usually don't care if there would be a warning inside system headers, we
only check user-code. It's okay if internal implementation would give a warning
- it is usually filtered out.
I've checked `common_type` and it works fine https://godbolt.org/z/9WjKse9fd.
Maybe variadic templates were forgotten when the check was originally
implemented. Could you add a test-case for it then and put back `tuple` and
`variant`. In limitation, should be only nested namespaces left.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +155,10 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"compare_three_way_result",
+"common_comparison_category",
localspook wrote:
Hm, I've looked into it some more, and it turns out we do already have
recursive traits: `common_type` and `common_reference` (also `conjunction` and
`disjunction`, but those are "metatraits", they're somewhat different). So
maybe recursive traits are alright? I've looked at some implementations, and I
thought they were written like this:
```cpp
template <...>
struct trait {
using type = trait<...>::type; // Triggers the check.
};
```
but actually they seem to be written like this:
```cpp
template <...>
struct trait : trait<...> {}; // No warning.
```
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor requested changes to this pull request. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -38,3 +38,10 @@ Options #define IS_SIGNED(T) std::is_signed::value Defaults to `false`. + +Limitations +--- + +Does not currently diagnose uses of ``std::chrono::is_clock``, +``std::chrono::treat_as_floating_point``, ``std::tuple_element``, +or ``std::variant_alternative``. vbvictor wrote: Write more general description for future-proof. Does not currently diagnose variadic type traits (e.g. ``std::tuple_element``) and type traits with nested namespace specifiers (e.g. ``std::chrono::is_clock``). https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +155,10 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"compare_three_way_result",
+"common_comparison_category",
vbvictor wrote:
This also has variadic templates
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"tuple_element",
localspook wrote:
Done
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook updated
https://github.com/llvm/llvm-project/pull/147074
>From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:42:54 -0700
Subject: [PATCH 1/5] [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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
>From 930db523cdbe6bf44b334a17667229e3586981aa Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:59:02 -0700
Subject: [PATCH 2/5] Whoops, didn't exclude `treat_as_floating_point_v` or
`is_clock_v`
---
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 92e6f61a6d9d4..aaf9d08c63b2e 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -31,7 +31,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_bind_expression",
"is_bounded_array",
"is_class",
-"is_clock",
"is_compound",
"is_const",
"is_constructible",
@@ -117,7 +116,6 @@ static const llvm::StringSet<> ValueTraits = {
"ratio_not_equal",
"reference_constructs_from_temporary",
"reference_converts_from_temporary",
-"treat_as_floating_point",
"tuple_size",
"uses_allocator",
"variant_size",
>From 13dcaabd66610972db0e6e52e49bb63878e248a6 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 08:15:53 -0700
Subject: [PATCH 3/5] clang-format
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"tuple_element",
vbvictor wrote:
I'd also suggest adding "Limitation" section in check docs. Search in docs
directory for reference. That would be helpful.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
localspook wrote: I've changed the tests to use `-std=c++17-or-later`, but I don't think we need to add tests for the new traits because they wouldn't exercise any new codepaths. It's not like we only match on `compare_three_way_result_t` if compiling in C++20, no, we match on all traits in all modes. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"tuple_element",
vbvictor wrote:
Please remove other recursive traits as well, `variant_alternative` is also one
of them.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"tuple_element",
localspook wrote:
Good catch -- recursive traits are indeed problematic, the check fires on the
recursive use in the definition. Unfortunately I'm not confident fixing it
(that's kinda why I'm not addressing `treat_as_floating_point_v` or
`is_clock_v` either...), so I've just removed `tuple_element` and added a
`FIXME`.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook updated
https://github.com/llvm/llvm-project/pull/147074
>From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:42:54 -0700
Subject: [PATCH 1/4] [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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
>From 930db523cdbe6bf44b334a17667229e3586981aa Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:59:02 -0700
Subject: [PATCH 2/4] Whoops, didn't exclude `treat_as_floating_point_v` or
`is_clock_v`
---
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 92e6f61a6d9d4..aaf9d08c63b2e 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -31,7 +31,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_bind_expression",
"is_bounded_array",
"is_class",
-"is_clock",
"is_compound",
"is_const",
"is_constructible",
@@ -117,7 +116,6 @@ static const llvm::StringSet<> ValueTraits = {
"ratio_not_equal",
"reference_constructs_from_temporary",
"reference_converts_from_temporary",
-"treat_as_floating_point",
"tuple_size",
"uses_allocator",
"variant_size",
>From 13dcaabd66610972db0e6e52e49bb63878e248a6 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 08:15:53 -0700
Subject: [PATCH 3/4] clang-format
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
localspook wrote: Mostly manually: I took a list of [all standard library symbols](https://timsong-cpp.github.io/cppwp/libraryindex), used a hacky regex to find `foo`/`foo_[tv]` pairs, filtered out the false positives, diffed against the check's current list, and added what was missing. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
vbvictor wrote: I wonder did you find this somehow automatically or manually? https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+"tuple_element",
vbvictor wrote:
There are no tests that will handle recursive traits (AFAIK there weren't any
recursive trait in the list before your changes).
Could you add tests for `tuple_element` to check if it will work correctly.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor requested changes to this pull request. Thank you for the patch! Could you please add tests with new traits from C++20, 23, 26 standards to make sure we get warning. You will need to change `-std=c++17` to `-std=c++17-or-later` in tests. https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/vbvictor edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook updated
https://github.com/llvm/llvm-project/pull/147074
>From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:42:54 -0700
Subject: [PATCH 1/3] [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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
>From 930db523cdbe6bf44b334a17667229e3586981aa Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:59:02 -0700
Subject: [PATCH 2/3] Whoops, didn't exclude `treat_as_floating_point_v` or
`is_clock_v`
---
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 92e6f61a6d9d4..aaf9d08c63b2e 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -31,7 +31,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_bind_expression",
"is_bounded_array",
"is_class",
-"is_clock",
"is_compound",
"is_const",
"is_constructible",
@@ -117,7 +116,6 @@ static const llvm::StringSet<> ValueTraits = {
"ratio_not_equal",
"reference_constructs_from_temporary",
"reference_converts_from_temporary",
-"treat_as_floating_point",
"tuple_size",
"uses_allocator",
"variant_size",
>From 13dcaabd66610972db0e6e52e49bb63878e248a6 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 08:15:53 -0700
Subject: [PATCH 3/3] clang-format
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
@@ -130,6 +149,12 @@ static const llvm::StringSet<> TypeTraits = {
"result_of",
"invoke_result",
"type_identity",
+ "tuple_element",
localspook wrote:
The `TypeTraits` are already not in alphabetical order (`ValueTraits` are
though), and I didn't want to reorder them in this PR because it would make it
harder to see which traits were being added.
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook edited https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
https://github.com/localspook updated
https://github.com/llvm/llvm-project/pull/147074
>From 7ad6f7b8663980183e8bb8e79843942870e36267 Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:42:54 -0700
Subject: [PATCH 1/2] [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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
>From 930db523cdbe6bf44b334a17667229e3586981aa Mon Sep 17 00:00:00 2001
From: Victor Chernyakin
Date: Fri, 4 Jul 2025 07:59:02 -0700
Subject: [PATCH 2/2] Whoops, didn't exclude `treat_as_floating_point_v` or
`is_clock_v`
---
clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp | 2 --
1 file changed, 2 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 92e6f61a6d9d4..aaf9d08c63b2e 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -31,7 +31,6 @@ static const llvm::StringSet<> ValueTraits = {
"is_bind_expression",
"is_bounded_array",
"is_class",
-"is_clock",
"is_compound",
"is_const",
"is_constructible",
@@ -117,7 +116,6 @@ static const llvm::StringSet<> ValueTraits = {
"ratio_not_equal",
"reference_constructs_from_temporary",
"reference_converts_from_temporary",
-"treat_as_floating_point",
"tuple_size",
"uses_allocator",
"variant_size",
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
llvmbot wrote:
@llvm/pr-subscribers-clang-tidy
Author: Victor Chernyakin (localspook)
Changes
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/147074.diff
2 Files Affected:
- (modified) clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp (+27)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3)
``diff
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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
``
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
llvmbot wrote:
@llvm/pr-subscribers-clang-tools-extra
Author: Victor Chernyakin (localspook)
Changes
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/147074.diff
2 Files Affected:
- (modified) clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp (+27)
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+3)
``diff
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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
``
https://github.com/llvm/llvm-project/pull/147074
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/147074 ___ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Teach `modernize-type-traits` about more type traits (PR #147074)
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
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
+ ` check by detecting more type
traits.
+
- Improved :doc:`modernize-use-default-member-init
` check by matching
arithmetic operations, ``constexpr`` and ``static`` values, and detecting
___
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
