[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 18 06:57:48 PST 2025
================
@@ -0,0 +1,84 @@
+// RUN: %check_clang_tidy -std=c++11-or-later %s readability-use-numeric-limits %t
+#include <stdint.h>
+
+void constants() {
+ // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant -128 is being utilized. Consider using std::numeric_limits<int8_t>::min() instead [readability-use-numeric-limits]
+ // CHECK-FIXES: int8_t _ = std::numeric_limits<int8_t>::min();
+ int8_t _ = -128;
+
+ // CHECK-MESSAGES: :[[@LINE+2]]:14: warning: The constant 127 is being utilized. Consider using std::numeric_limits<int8_t>::max() instead [readability-use-numeric-limits]
+ // CHECK-FIXES: int8_t _ = std::numeric_limits<int8_t>::max();
+ int8_t _ = +127;
----------------
vbvictor wrote:
Please, don't use placeholder variables in test files.
Although it is already supported in gcc14 and clang18, I believe tests which say `c++11-or-later` should be able to compile with any compiler which has `c++11` support.
https://github.com/llvm/llvm-project/pull/127430
More information about the cfe-commits
mailing list