[clang-tools-extra] [clang-tidy] Avoid overflow when dumping unsigned integer values (PR #85060)

Piotr Zegar via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 13 10:10:06 PDT 2024


================
@@ -408,17 +408,26 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
     /// Stores an option with the check-local name \p LocalName with
     /// integer value \p Value to \p Options.
     template <typename T>
-    std::enable_if_t<std::is_integral_v<T>>
+    std::enable_if_t<std::is_integral_v<T> && std::is_signed<T>::value>
     store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
           T Value) const {
       storeInt(Options, LocalName, Value);
     }
 
+    /// Stores an option with the check-local name \p LocalName with
+    /// unsigned integer value \p Value to \p Options.
+    template <typename T>
+    std::enable_if_t<std::is_unsigned<T>::value>
+    store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
+          T Value) const {
+      storeUnsigned(Options, LocalName, Value);
+    }
+
     /// Stores an option with the check-local name \p LocalName with
     /// integer value \p Value to \p Options. If the value is empty
     /// stores ``
     template <typename T>
-    std::enable_if_t<std::is_integral_v<T>>
+    std::enable_if_t<std::is_integral_v<T> && std::is_signed<T>::value>
----------------
PiotrZSL wrote:

instead of adding new version for optional, just call in this method `store` instead of storeInt,

https://github.com/llvm/llvm-project/pull/85060


More information about the cfe-commits mailing list