[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:07 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);
----------------
PiotrZSL wrote:

jinstead of using std::is_signed just use:
```
if constexpr(std::is_signed_v<T>)
   storeInt(Options, LocalName, Value);
else
  storeUnsigned(Options, LocalName, Value);
```

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


More information about the cfe-commits mailing list