================ @@ -0,0 +1,84 @@ +// RUN: %check_clang_tidy %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 a = std::numeric_limits<int8_t>::min(); + int8_t a = -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 b = std::numeric_limits<int8_t>::max(); + int8_t b = +127; + + // 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 c = std::numeric_limits<int8_t>::max(); + int8_t c = 127; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -32768 is being utilized. Consider using std::numeric_limits<int16_t>::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t d = std::numeric_limits<int16_t>::min(); + int16_t d = -32768; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being utilized. Consider using std::numeric_limits<int16_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t e = std::numeric_limits<int16_t>::max(); + int16_t e = +32767; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 32767 is being utilized. Consider using std::numeric_limits<int16_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int16_t f = std::numeric_limits<int16_t>::max(); + int16_t f = 32767; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -2147483648 is being utilized. Consider using std::numeric_limits<int32_t>::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t g = std::numeric_limits<int32_t>::min(); + int32_t g = -2147483648; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is being utilized. Consider using std::numeric_limits<int32_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t h = std::numeric_limits<int32_t>::max(); + int32_t h = +2147483647; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 2147483647 is being utilized. Consider using std::numeric_limits<int32_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int32_t i = std::numeric_limits<int32_t>::max(); + int32_t i = 2147483647; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant -9223372036854775808 is being utilized. Consider using std::numeric_limits<int64_t>::min() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t j = std::numeric_limits<int64_t>::min(); + int64_t j = -9223372036854775808; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 9223372036854775807 is being utilized. Consider using std::numeric_limits<int64_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t k = std::numeric_limits<int64_t>::max(); + int64_t k = +9223372036854775807; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 9223372036854775807 is being utilized. Consider using std::numeric_limits<int64_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: int64_t l = std::numeric_limits<int64_t>::max(); + int64_t l = 9223372036854775807; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being utilized. Consider using std::numeric_limits<uint8_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint8_t m = std::numeric_limits<uint8_t>::max(); + uint8_t m = 255; + + // CHECK-MESSAGES: :[[@LINE+2]]:15: warning: The constant 255 is being utilized. Consider using std::numeric_limits<uint8_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint8_t n = std::numeric_limits<uint8_t>::max(); + uint8_t n = +255; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being utilized. Consider using std::numeric_limits<uint16_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint16_t o = std::numeric_limits<uint16_t>::max(); + uint16_t o = 65535; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 65535 is being utilized. Consider using std::numeric_limits<uint16_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint16_t p = std::numeric_limits<uint16_t>::max(); + uint16_t p = +65535; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is being utilized. Consider using std::numeric_limits<uint32_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint32_t q = std::numeric_limits<uint32_t>::max(); + uint32_t q = 4294967295; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 4294967295 is being utilized. Consider using std::numeric_limits<uint32_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint32_t r = std::numeric_limits<uint32_t>::max(); + uint32_t r = +4294967295; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 18446744073709551615 is being utilized. Consider using std::numeric_limits<uint64_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint64_t s = std::numeric_limits<uint64_t>::max(); + uint64_t s = 18446744073709551615; + + // CHECK-MESSAGES: :[[@LINE+2]]:16: warning: The constant 18446744073709551615 is being utilized. Consider using std::numeric_limits<uint64_t>::max() instead [readability-use-numeric-limits] + // CHECK-FIXES: uint64_t t = std::numeric_limits<uint64_t>::max(); + uint64_t t = +18446744073709551615; ---------------- vbvictor wrote:
With `BareIntegerMatcher` you can try writing `ignoringParenImpCasts` at least in two places and experiment with the outcome. 1. `ignoringParenImpCasts(integerLiteral(allOf(...)))` 2. `unless(ignoringParenImpCasts(hasParent(...)))` I ran tests on this 5 values and got one match as follows: ```cpp int16_t a1 = -(32768); int16_t a2 = +(32768); int16_t a3 = (+32768); int16_t a4 = (-32768); // match (std::numeric_limits<int16_t>::min()) int16_t a5 = (32768); ``` My suggestion is that you should add these cases in test file and correct your matchers to detect some of cases (preferably all). Also, state explicitly in tests that cases which are left are not matched by design. This may avoid confusion in the future. https://github.com/llvm/llvm-project/pull/127430 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits