[clang-tools-extra] [clang-tidy] Add modernize-use-to-underlying check (PR #210459)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 21 22:50:53 PDT 2026
================
@@ -0,0 +1,55 @@
+// RUN: %check_clang_tidy -check-suffixes=IGNORE -std=c++23-or-later %s \
+// RUN: modernize-use-to-underlying %t -- \
+// RUN: -config="{CheckOptions: {modernize-use-to-underlying.ImpreciseCasts: Ignore}}"
+// RUN: %check_clang_tidy -check-suffixes=WARN -std=c++23-or-later %s \
+// RUN: modernize-use-to-underlying %t -- \
+// RUN: -config="{CheckOptions: {modernize-use-to-underlying.ImpreciseCasts: Warn}}"
+// RUN: %check_clang_tidy -check-suffixes=PRESERVE -std=c++23-or-later %s \
+// RUN: modernize-use-to-underlying %t -- \
+// RUN: -config="{CheckOptions: {modernize-use-to-underlying.ImpreciseCasts: PreserveType}}"
+// RUN: %check_clang_tidy -check-suffixes=UNDERLYING -std=c++23-or-later %s \
+// RUN: modernize-use-to-underlying %t -- \
+// RUN: -config="{CheckOptions: {modernize-use-to-underlying.ImpreciseCasts: UseUnderlyingType}}"
+
+// CHECK-FIXES-WARN: #include <utility>
+// CHECK-FIXES-PRESERVE: #include <utility>
+// CHECK-FIXES-UNDERLYING: #include <utility>
+
+namespace std {
+template <typename T>
+constexpr __underlying_type(T) to_underlying(T value) noexcept {
+ return static_cast<__underlying_type(T)>(value);
+}
+} // namespace std
----------------
zwuis wrote:
Move this to `clang-tools-extra/test/clang-tidy/checkers/Inputs/Headers/std/utility`.
https://github.com/llvm/llvm-project/pull/210459
More information about the cfe-commits
mailing list