Repository: onnx/onnx
Pull request #6832: Fix clang-tidy warnings
Author: login: cyyever
Labels: name: run release CIs
description: Use this label to trigger release tests in CI
Created: 2025-03-22T16:08:12Z | Merged: 2025-03-23T11:38:40Z

### Description
<!-- - Describe your changes. -->
Fix all current clang-tidy-19 warnings
### Motivation and Context
Better code.
<!-- - Why is this change required? What problem does it solve? -->
<!-- - If it fixes an open issue, please link to the issue here. -->



Diff:
diff --git a/.clang-tidy b/.clang-tidy
index dcd75e65145..f995b880151 100644
--- a/.clang-tidy
+++ b/.clang-tidy
@@ -5,7 +5,6 @@
 Checks: >-
   -*,
   bugprone-*,
-  -bugprone-branch-clone,
   -bugprone-easily-swappable-parameters,
   -bugprone-lambda-function-name,
   -bugprone-macro-parentheses,
@@ -15,7 +14,6 @@ Checks: >-
   clang-analyzer-.*,
   cppcoreguidelines-avoid-goto,
   cppcoreguidelines-interfaces-global-init,
-  cppcoreguidelines-init-variables,
   cppcoreguidelines-no-malloc,
   cppcoreguidelines-prefer-member-initializer,
   cppcoreguidelines-pro-type-member-init,
@@ -34,7 +32,6 @@ Checks: >-
   -misc-use-anonymous-namespace,
   modernize-*,
   -modernize-concat-nested-namespaces,
-  -modernize-raw-string-literal,
   -modernize-return-braced-init-list,
   -modernize-use-auto,
   -modernize-use-trailing-return-type,
@@ -46,14 +43,12 @@ Checks: >-
   readability-non-const-parameter,
   readability-redundant*
   readability-simplify*,
-  readability-string-compare,
-  -readability-redundant-access-specifiers,
-  -readability-redundant-control-flow,
   readability-static-accessed-through-instance,
   readability-static-definition-in-anonymous-namespace,
   readability-string-compare,
   readability-suspicious-call-argument,
   readability-uniqueptr-delete-release,
+  -readability-redundant-access-specifiers,
 
 CheckOptions:
   # `cppcoreguidelines-special-member-functions` is enabled, refer to https://en.cppreference.com/w/cpp/language/rule_of_three
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e9c47609475..c193e51caab 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -638,6 +638,7 @@ if(MSVC)
   endif()
 else()
   target_compile_options(onnx PRIVATE -Wall -Wextra)
+  target_compile_options(onnx_proto PRIVATE -Wall -Wextra)
   if(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13)
     target_compile_options(onnx PRIVATE "-Wno-stringop-overflow")
     target_compile_options(onnx_proto PRIVATE "-Wno-stringop-overflow")
diff --git a/onnx/checker.h b/onnx/checker.h
index 502a2235733..9035ea34ca3 100644
--- a/onnx/checker.h
+++ b/onnx/checker.h
@@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
 #include "onnx/string_utils.h"
 
 namespace ONNX_NAMESPACE {
diff --git a/onnx/common/interned_strings.h b/onnx/common/interned_strings.h
index f14465b7174..c2237fdf291 100644
--- a/onnx/common/interned_strings.h
+++ b/onnx/common/interned_strings.h
@@ -190,7 +190,7 @@ namespace ONNX_NAMESPACE {
   _(block_size)                     \
   _(output_dtype)
 
-enum BuiltinSymbol {
+enum BuiltinSymbol : std::uint8_t {
 #define DEFINE_SYMBOL(s) k##s,
   FORALL_BUILTIN_SYMBOLS(DEFINE_SYMBOL)
 #undef DEFINE_SYMBOL
diff --git a/onnx/common/ir.h b/onnx/common/ir.h
index bf5f6d1f2e2..37a20eb6d37 100644
--- a/onnx/common/ir.h
+++ b/onnx/common/ir.h
@@ -82,8 +82,8 @@ class ResourceGuard final {
 
 struct Dimension final {
   Dimension() : is_unknown(true), is_int(false), dim(-1) {}
-  Dimension(std::string param) : is_unknown(false), is_int(false), dim(-1), param(std::move(param)) {} // NOLINT
-  Dimension(int64_t dim) : is_unknown(false), is_int(true), dim(dim) {} // NOLINT
+  explicit Dimension(std::string param) : is_unknown(false), is_int(false), dim(-1), param(std::move(param)) {}
+  explicit Dimension(int64_t dim) : is_unknown(false), is_int(true), dim(dim) {}
 
   bool is_unknown;
   bool is_int;
@@ -109,6 +109,7 @@ enum class AttributeKind : uint8_t {
 };
 
 static inline const char* toString(AttributeKind kind) {
+  // NOLINTNEXTLINE(modernize-avoid-c-arrays)
   static constexpr const char* names[] = {"f", "fs", "i", "is", "s", "ss", "t", "ts", "g", "gs", "tp", "tps"};
   ONNX_ASSERT(size_t(kind) < sizeof(names) / sizeof(const char*));
   return names[int(kind)];
@@ -127,7 +128,7 @@ template <typename T, AttributeKind Kind>
 struct ScalarAttributeValue final : public AttributeValue {
   using ConstructorType = const T&;
   using ValueType = T;
-  ScalarAttributeValue(Symbol name, ConstructorType value_) : AttributeValue(name), value_(value_) {}
+  ScalarAttributeValue(Symbol name, ConstructorType value_) : AttributeValue(name), value_(std::move(value_)) {}
   ValueType& value() {
     return value_;
   }
@@ -180,6 +181,7 @@ using TypeProtosAttr = VectorAttributeValue<TypeProto, AttributeKind::tps>;
 // we return Derived* pointers because Nodes are normally held as pointers.
 template <typename Derived>
 struct Attributes {
+  // NOLINTNEXTLINE(bugprone-crtp-constructor-accessibility)
   Attributes() = default;
 
   void copyAttributes(const Attributes& rhs) {
diff --git a/onnx/common/ir_pb_converter.cc b/onnx/common/ir_pb_converter.cc
index e2b1fbb9729..6f867f8b3e4 100644
--- a/onnx/common/ir_pb_converter.cc
+++ b/onnx/common/ir_pb_converter.cc
@@ -43,6 +43,8 @@ static Tensor tensorProtoToTensor(const ONNX_NAMESPACE::TensorProto& tp) {
     case ONNX_NAMESPACE::TensorProto_DataType_FLOAT16:
     case ONNX_NAMESPACE::TensorProto_DataType_BFLOAT16:
     case ONNX_NAMESPACE::TensorProto_DataType_BOOL:
+    case ONNX_NAMESPACE::TensorProto_DataType_UINT4:
+    case ONNX_NAMESPACE::TensorProto_DataType_INT4:
     case ONNX_NAMESPACE::TensorProto_DataType_INT8:
     case ONNX_NAMESPACE::TensorProto_DataType_INT16:
     case ONNX_NAMESPACE::TensorProto_DataType_INT32:
@@ -90,6 +92,8 @@ static Tensor tensorProtoToTensor(const ONNX_NAMESPACE::TensorProto& tp) {
       break;
     }
     case ONNX_NAMESPACE::TensorProto_DataType_UNDEFINED:
+      [[fallthrough]];
+    default:
       fail_convert("Unknown tensor data type");
   }
 
@@ -391,7 +395,8 @@ std::unique_ptr<Graph> graphProtoToGraph(const ONNX_NAMESPACE::GraphProto& gp, b
 std::unique_ptr<Graph> ImportModelProto(const ModelProto& mp) {
   if (!mp.has_ir_version()) {
     return nullptr;
-  } else if (mp.ir_version() <= 1) {
+  }
+  if (mp.ir_version() <= 1) {
     // ir_version=1 is not supported and ir_version=0 is illegal
     return nullptr;
   }
@@ -436,7 +441,14 @@ static void encodeTensor(ONNX_NAMESPACE::TensorProto* p, const Tensor& tensor) {
     }
     case ONNX_NAMESPACE::TensorProto_DataType_FLOAT16:
     case ONNX_NAMESPACE::TensorProto_DataType_BFLOAT16:
+    case ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E4M3FN:
+    case ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E4M3FNUZ:
+    case ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E5M2:
+    case ONNX_NAMESPACE::TensorProto_DataType_FLOAT8E5M2FNUZ:
+    case ONNX_NAMESPACE::TensorProto_DataType_FLOAT4E2M1:
     case ONNX_NAMESPACE::TensorProto_DataType_BOOL:
+    case ONNX_NAMESPACE::TensorProto_DataType_INT4:
+    case ONNX_NAMESPACE::TensorProto_DataType_UINT4:
     case ONNX_NAMESPACE::TensorProto_DataType_INT8:
     case ONNX_NAMESPACE::TensorProto_DataType_INT16:
     case ONNX_NAMESPACE::TensorProto_DataType_INT32:
@@ -474,6 +486,8 @@ static void encodeTensor(ONNX_NAMESPACE::TensorProto* p, const Tensor& tensor) {
       break;
     }
     case ONNX_NAMESPACE::TensorProto_DataType_UNDEFINED:
+      [[fallthrough]];
+    default:
       fail_convert("Unknown tensor data type");
   }
   if (tensor.is_raw_data()) {
diff --git a/onnx/common/status.h b/onnx/common/status.h
index 5e29326d89c..2e48896fe7b 100644
--- a/onnx/common/status.h
+++ b/onnx/common/status.h
@@ -6,6 +6,7 @@
 
 #pragma once
 
+#include <cstdint>
 #include <memory>
 #include <ostream>
 #include <string>
@@ -14,13 +15,13 @@
 namespace ONNX_NAMESPACE {
 namespace Common {
 
-enum class StatusCategory {
+enum class StatusCategory : std::uint8_t {
   NONE = 0,
   CHECKER = 1,
   OPTIMIZER = 2,
 };
 
-enum class StatusCode {
+enum class StatusCode : std::uint8_t {
   OK = 0,
   FAIL = 1,
   INVALID_ARGUMENT = 2,
diff --git a/onnx/defs/attr_proto_util.cc b/onnx/defs/attr_proto_util.cc
index 612b82615b2..726779edf0f 100644
--- a/onnx/defs/attr_proto_util.cc
+++ b/onnx/defs/attr_proto_util.cc
@@ -7,46 +7,49 @@
 #include "attr_proto_util.h"
 
 #include <string>
+#include <utility>
 #include <vector>
 
 namespace ONNX_NAMESPACE {
 
-#define ADD_BASIC_ATTR_IMPL(type, enumType, field)                                \
-  AttributeProto MakeAttribute(const std::string& attr_name, const type& value) { \
-    AttributeProto a;                                                             \
-    a.set_name(attr_name);                                                        \
-    a.set_type(enumType);                                                         \
-    a.set_##field(value);                                                         \
-    return a;                                                                     \
+#define ADD_BASIC_ATTR_IMPL(type, enumType, field)                  \
+  AttributeProto MakeAttribute(std::string attr_name, type value) { \
+    AttributeProto a;                                               \
+    a.set_name(std::move(attr_name));                               \
+    a.set_type(enumType);                                           \
+    a.set_##field(value);                                           \
+    return a;                                                       \
   }
 
-#define ADD_ATTR_IMPL(type, enumType, field)                                      \
-  AttributeProto MakeAttribute(const std::string& attr_name, const type& value) { \
+#define ADD_ATTR_IMPL(type, enumType, field)                        \
+  AttributeProto MakeAttribute(std::string attr_name, type value) { \
+    AttributeProto a;                                               \
+    a.set_name(std::move(attr_name));                               \
+    a.set_type(enumType);                                           \
+    *(a.mutable_##field()) = std::move(value);                      \
+    return a;                                                       \
+  }
+
+#define ADD_LIST_ATTR_IMPL(type, enumType, field)                                 \
+  AttributeProto MakeAttribute(std::string attr_name, std::vector<type> values) { \
     AttributeProto a;                                                             \
-    a.set_name(attr_name);                                                        \
+    a.set_name(std::move(attr_name));                                             \
     a.set_type(enumType);                                                         \
-    *(a.mutable_##field()) = value;                                               \
+    for (auto&& val : std::move(values)) {                                        \
+      *(a.mutable_##field()->Add()) = std::move(val);                             \
+    }                                                                             \
     return a;                                                                     \
   }
 
-#define ADD_LIST_ATTR_IMPL(type, enumType, field)                                               \
-  AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<type>& values) { \
-    AttributeProto a;                                                                           \
-    a.set_name(attr_name);                                                                      \
-    a.set_type(enumType);                                                                       \
-    for (const auto& val : values) {                                                            \
-      *(a.mutable_##field()->Add()) = val;                                                      \
-    }                                                                                           \
-    return a;                                                                                   \
-  }
-
 ADD_BASIC_ATTR_IMPL(float, AttributeProto_AttributeType_FLOAT, f)
 ADD_BASIC_ATTR_IMPL(int64_t, AttributeProto_AttributeType_INT, i)
 ADD_BASIC_ATTR_IMPL(std::string, AttributeProto_AttributeType_STRING, s)
 ADD_ATTR_IMPL(TensorProto, AttributeProto_AttributeType_TENSOR, t)
 ADD_ATTR_IMPL(GraphProto, AttributeProto_AttributeType_GRAPH, g)
 ADD_ATTR_IMPL(TypeProto, AttributeProto_AttributeType_TYPE_PROTO, tp)
+// NOLINTNEXTLINE(performance-unnecessary-value-param)
 ADD_LIST_ATTR_IMPL(float, AttributeProto_AttributeType_FLOATS, floats)
+// NOLINTNEXTLINE(performance-unnecessary-value-param)
 ADD_LIST_ATTR_IMPL(int64_t, AttributeProto_AttributeType_INTS, ints)
 ADD_LIST_ATTR_IMPL(std::string, AttributeProto_AttributeType_STRINGS, strings)
 ADD_LIST_ATTR_IMPL(TensorProto, AttributeProto_AttributeType_TENSORS, tensors)
diff --git a/onnx/defs/attr_proto_util.h b/onnx/defs/attr_proto_util.h
index 4b6c8e631ac..64b07292dfa 100644
--- a/onnx/defs/attr_proto_util.h
+++ b/onnx/defs/attr_proto_util.h
@@ -13,16 +13,18 @@
 
 namespace ONNX_NAMESPACE {
 
-AttributeProto MakeAttribute(const std::string& attr_name, const float& value);
-AttributeProto MakeAttribute(const std::string& attr_name, const int64_t& value);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::string& value);
-AttributeProto MakeAttribute(const std::string& attr_name, const TensorProto& value);
-AttributeProto MakeAttribute(const std::string& attr_name, const GraphProto& value);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<float>& values);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<int64_t>& values);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<std::string>& values);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<TensorProto>& values);
-AttributeProto MakeAttribute(const std::string& attr_name, const std::vector<GraphProto>& values);
+AttributeProto MakeAttribute(std::string attr_name, float value);
+AttributeProto MakeAttribute(std::string attr_name, int64_t value);
+AttributeProto MakeAttribute(std::string attr_name, std::string value);
+AttributeProto MakeAttribute(std::string attr_name, TensorProto value);
+AttributeProto MakeAttribute(std::string attr_name, GraphProto value);
+AttributeProto MakeAttribute(std::string attr_name, TypeProto value);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<float> values);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<int64_t> values);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<std::string> values);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<TensorProto> values);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<GraphProto> values);
+AttributeProto MakeAttribute(std::string attr_name, std::vector<TypeProto> values);
 
 // Make a "reference" attribute for a node in a function body.
 // <attr_name> specifies the attribute name of both the function node and its
diff --git a/onnx/defs/function.h b/onnx/defs/function.h
index ef6475d5715..78e7a454b5d 100644
--- a/onnx/defs/function.h
+++ b/onnx/defs/function.h
@@ -170,6 +170,7 @@ class FunctionBuilder {
     if constexpr (sizeof...(args) % 2 == 0) {
       return AddAttributes(args...);
     }
+    return *this;
   }
 
   FunctionBuilder& Const(const std::string& name, const TensorProto& tensor) {
diff --git a/onnx/defs/parser.h b/onnx/defs/parser.h
index 29fe315accd..973369d4d9d 100644
--- a/onnx/defs/parser.h
+++ b/onnx/defs/parser.h
@@ -124,7 +124,7 @@ class AttributeTypeNameMap : public StringIntMap<AttributeTypeNameMap> {
 
 class KeyWordMap {
  public:
-  enum class KeyWord {
+  enum class KeyWord : std::uint8_t {
     NONE,
     IR_VERSION,
     OPSET_IMPORT,
@@ -264,7 +264,7 @@ class ParserBase {
     return (next_ >= end_);
   }
 
-  enum class LiteralType { UNDEFINED, INT_LITERAL, FLOAT_LITERAL, STRING_LITERAL };
+  enum class LiteralType : std::uint8_t { UNDEFINED, INT_LITERAL, FLOAT_LITERAL, STRING_LITERAL };
 
   struct Literal {
     LiteralType type{LiteralType::UNDEFINED};
diff --git a/onnx/defs/schema.h b/onnx/defs/schema.h
index 3df4b7a9e29..e2e53493e42 100644
--- a/onnx/defs/schema.h
+++ b/onnx/defs/schema.h
@@ -868,6 +868,7 @@ class ISchemaRegistry {
   virtual ~ISchemaRegistry() = default;
 
   virtual const OpSchema*
+  // NOLINTNEXTLINE(google-default-arguments)
   GetSchema(const std::string& key, const int maxInclusiveVersion, const std::string& domain = ONNX_DOMAIN) const = 0;
 };
 
@@ -1158,6 +1159,7 @@ class OpSchemaRegistry final : public ISchemaRegistry {
 
   static OpSchemaRegistry* Instance();
 
+  // NOLINTNEXTLINE(google-default-arguments)
   const OpSchema* GetSchema(
       const std::string& key,
       const int maxInclusiveVersion,
@@ -1255,26 +1257,11 @@ OpSchema GetOpSchema();
 #define ONNX_PREVIEW_TRAINING_OPERATOR_SET_SCHEMA(name, ver, impl) \
   ONNX_OPERATOR_SET_SCHEMA_EX(name, OnnxPreview, AI_ONNX_PREVIEW_TRAINING_DOMAIN, ver, true, impl)
 
-// Defines specialization of GetOpSchema for a class whose name is determined
-// based on a convention using name, domain, and version.  Operator schema are
-// normally included in operator sets and registered in OpSchemaRegistry::map().
-// In this case, callers should set dbg_included_in_static_opset to true.  This
-// assists with runtime validation in DEBUG builds ensuring the intended set
-// of operator schema is registered.
-#define ONNX_OPERATOR_SET_SCHEMA_EX(name, domain, domain_str, ver, dbg_included_in_static_opset, impl)  \
-  class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(domain, ver, name);                                         \
-  template <>                                                                                           \
-  OpSchema GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(domain, ver, name)>() {                      \
-    return impl.SetName(#name).SetDomain(domain_str).SinceVersion(ver).SetLocation(__FILE__, __LINE__); \
-  }                                                                                                     \
-  static size_t dbg_count_check_##name##_##domain##_ver##ver [[maybe_unused]] =                         \
-      (dbg_included_in_static_opset) ? ONNX_DBG_INCREMENT_COUNT_IN_OPSETS() : 0;
 #ifdef NDEBUG
 #define ONNX_DBG_INCREMENT_COUNT_IN_OPSETS() 0
+#define ONNX_OPERATOR_SET_SCHEMA_DEBUG_VARIABLE(name, domain, ver, dbg_included_in_static_opset) \
+  static size_t dbg_count_check_##name##_##domain##_ver##ver [[maybe_unused]] = 0
 #else
-#define ONNX_DBG_INCREMENT_COUNT_IN_OPSETS() DbgOperatorSetTracker::Instance().IncrementCount()
-#define ONNX_DBG_GET_COUNT_IN_OPSETS() DbgOperatorSetTracker::Instance().GetCount()
-
 class DbgOperatorSetTracker {
  public:
   static DbgOperatorSetTracker& Instance();
@@ -1290,6 +1277,29 @@ class DbgOperatorSetTracker {
  private:
   size_t count_ = 0;
 };
+#define ONNX_DBG_INCREMENT_COUNT_IN_OPSETS() DbgOperatorSetTracker::Instance().IncrementCount()
+#define ONNX_OPERATOR_SET_SCHEMA_DEBUG_VARIABLE(name, domain, ver, dbg_included_in_static_opset) \
+  static size_t dbg_count_check_##name##_##domain##_ver##ver [[maybe_unused]] =                  \
+      (dbg_included_in_static_opset) ? ONNX_DBG_INCREMENT_COUNT_IN_OPSETS() : 0;
+#endif
+
+// Defines specialization of GetOpSchema for a class whose name is determined
+// based on a convention using name, domain, and version.  Operator schema are
+// normally included in operator sets and registered in OpSchemaRegistry::map().
+// In this case, callers should set dbg_included_in_static_opset to true.  This
+// assists with runtime validation in DEBUG builds ensuring the intended set
+// of operator schema is registered.
+
+#define ONNX_OPERATOR_SET_SCHEMA_EX(name, domain, domain_str, ver, dbg_included_in_static_opset, impl)  \
+  class ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(domain, ver, name);                                         \
+  template <>                                                                                           \
+  OpSchema GetOpSchema<ONNX_OPERATOR_SET_SCHEMA_CLASS_NAME(domain, ver, name)>() {                      \
+    return impl.SetName(#name).SetDomain(domain_str).SinceVersion(ver).SetLocation(__FILE__, __LINE__); \
+  }                                                                                                     \
+  ONNX_OPERATOR_SET_SCHEMA_DEBUG_VARIABLE(domain, ver, name, dbg_included_in_static_opset)
+#ifndef NDEBUG
+#define ONNX_DBG_GET_COUNT_IN_OPSETS() DbgOperatorSetTracker::Instance().GetCount()
+
 #endif
 
 // Naming convention for operator schema classes
diff --git a/onnx/defs/sequence/defs.cc b/onnx/defs/sequence/defs.cc
index 34b06249937..e13423bc0a8 100644
--- a/onnx/defs/sequence/defs.cc
+++ b/onnx/defs/sequence/defs.cc
@@ -70,7 +70,7 @@ ONNX_OPERATOR_SET_SCHEMA(
             }
             input_elem_types.emplace_back(input_type->tensor_type().elem_type());
           }
-          if (std::adjacent_find(input_elem_types.begin(), input_elem_types.end(), std::not_equal_to<int>()) !=
+          if (std::adjacent_find(input_elem_types.begin(), input_elem_types.end(), std::not_equal_to()) !=
               input_elem_types.end()) {
             // not all input elem types are the same.
             fail_type_inference("Element type of inputs are expected to be the same.");
@@ -384,8 +384,7 @@ ONNX_OPERATOR_SET_SCHEMA(
                       " sum of split values=",
                       splitSizesSum);
                 }
-                if (std::adjacent_find(splitSizes.begin(), splitSizes.end(), std::not_equal_to<int64_t>()) ==
-                    splitSizes.end()) {
+                if (std::adjacent_find(splitSizes.begin(), splitSizes.end(), std::not_equal_to()) == splitSizes.end()) {
                   // all split sizes are the same.
                   return splitSizes[0];
                 }
diff --git a/onnx/defs/shape_inference.h b/onnx/defs/shape_inference.h
index 2a1fe8fca12..54a94f21725 100644
--- a/onnx/defs/shape_inference.h
+++ b/onnx/defs/shape_inference.h
@@ -522,9 +522,7 @@ inline void propagateElemTypeFromAttributeToOutput(
 }
 
 inline TensorShapeProto* getTensorMutableShape(TypeProto::ValueCase value_case, TypeProto& type) {
-  if (value_case == TypeProto::kTensorType) {
-    return type.mutable_tensor_type()->mutable_shape();
-  } else if (value_case == TypeProto::kSparseTensorType) {
+  if (value_case == TypeProto::kTensorType || value_case == TypeProto::kSparseTensorType) {
     return type.mutable_tensor_type()->mutable_shape();
   }
   return nullptr;
@@ -722,9 +720,8 @@ inline void mergeInDimensionInfo(
     } else {
       target_dim.set_dim_value(source_value);
     }
-  } else if (target_dim.has_dim_value()) {
+  } else if (target_dim.has_dim_value() || target_dim.has_dim_param()) {
     // if target has a value we preserve it so do nothing
-  } else if (target_dim.has_dim_param()) {
     // prefer target param over source
   } else if (source_dim.has_dim_param()) {
     target_dim.set_dim_param(source_dim.dim_param());
@@ -839,10 +836,9 @@ inline void unifyDim(const Dim& source_dim, Dim& target_dim) {
     } else {
       target_dim.set_dim_value(source_value);
     }
-  } else if (target_dim.has_dim_value()) {
+  } else if (target_dim.has_dim_value() || target_dim.has_dim_param()) {
     // if target has a value we preserve it.
     // we cannot set source dim value.
-  } else if (target_dim.has_dim_param()) {
     // prefer target param over source
     // we cannot currently unify the dim_params
   } else if (source_dim.has_dim_param()) {
diff --git a/onnx/defs/tensor/utils.h b/onnx/defs/tensor/utils.h
index 86308667175..6925e3e3b78 100644
--- a/onnx/defs/tensor/utils.h
+++ b/onnx/defs/tensor/utils.h
@@ -36,7 +36,7 @@ void resizeShapeInferenceHelper_opset7_to_10(
     const std::vector<float>& scales_data,
     TensorShapeProto* output_shape);
 
-enum class KeepAspectRatioPolicy {
+enum class KeepAspectRatioPolicy : std::uint8_t {
   STRETCH,
   NOT_LARGER,
   NOT_SMALLER,
diff --git a/onnx/defs/traditionalml/defs.cc b/onnx/defs/traditionalml/defs.cc
index 1688c9d378c..c852ece2564 100644
--- a/onnx/defs/traditionalml/defs.cc
+++ b/onnx/defs/traditionalml/defs.cc
@@ -382,8 +382,7 @@ ONNX_ML_OPERATOR_SET_SCHEMA(
             AttributeProto::TENSOR,
             OPTIONAL_VALUE)
         .TypeAndShapeInferenceFunction([](InferenceContext& ctx) {
-          int key_length, key_type;
-          std::tie(key_type, key_length) =
+          auto [key_type, key_length] =
               getAttributeElementTypeAndLength(ctx, {"keys_tensor", "keys_strings", "keys_int64s", "keys_floats"});
           if (key_type == TensorProto::UNDEFINED) {
             fail_shape_inference("At least one of keys_tensor, keys_strings, keys_int64s, keys_floats must be set.");
@@ -397,8 +396,7 @@ ONNX_ML_OPERATOR_SET_SCHEMA(
                 " are different, which is not permitted for LabelEncoders.");
           }
 
-          int value_length, value_type;
-          std::tie(value_type, value_length) = getAttributeElementTypeAndLength(
+          auto [value_type, value_length] = getAttributeElementTypeAndLength(
               ctx, {"values_tensor", "values_strings", "values_int64s", "values_floats"});
           if (value_type == TensorProto::UNDEFINED) {
             fail_shape_inference(
diff --git a/onnx/test/cpp/function_verify_test.cc b/onnx/test/cpp/function_verify_test.cc
index 788b9e0cf9c..b3dfacddcbd 100644
--- a/onnx/test/cpp/function_verify_test.cc
+++ b/onnx/test/cpp/function_verify_test.cc
@@ -229,7 +229,7 @@ struct FunctionTypeChecker {
   // forTypeVar: This is used to iterate through all possible bindings of type-values
   // to all type-variables used in the op schema, and invoke the type-checker for
   // each possible instantiation.
-  void forTypeVar(int i) {
+  void forTypeVar(size_t i) {
     auto& typeConstraintVector = schema.typeConstraintParams();
     if (i < typeConstraintVector.size()) {
       std::string typeVar = typeConstraintVector[i].type_param_str;
diff --git a/onnx/version_converter/adapters/resize_10_11.h b/onnx/version_converter/adapters/resize_10_11.h
index 046fa3f277c..42b3322e336 100644
--- a/onnx/version_converter/adapters/resize_10_11.h
+++ b/onnx/version_converter/adapters/resize_10_11.h
@@ -21,7 +21,7 @@ class Resize_10_11 final : public Adapter {
   explicit Resize_10_11() : Adapter("Resize", OpSetID(10), OpSetID(11)) {}
 
   void adapt_resize_10_11(const std::shared_ptr<Graph>& graph, Node* node) const {
-    int input_rank = node->inputs()[0]->sizes().size();
+    int64_t input_rank = node->inputs()[0]->sizes().size();
 
     Value* scales_input = node->inputs()[1];
     node->addInput(scales_input);


Reviews:
user: login: justinchuby
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-22T18:24:54Z
user: login: andife
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-22T19:09:20Z
user: login: justinchuby
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-22T21:07:41Z
user: login: cyyever
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-23T02:38:30Z
user: login: cyyever
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-23T02:54:38Z
user: login: justinchuby
state: COMMENTED
author_association: MEMBER
submitted_at: 2025-03-23T03:41:48Z
user: login: copilot-pull-request-reviewer[bot]
body: ## Pull Request Overview

This pull request aims to fix clang-tidy warnings by updating the configuration in the .clang-tidy file. Key changes include the removal of the "-modernize-raw-string-literal" and "-readability-redundant-control-flow" rules to address the warnings.

<details>
<summary>Files not reviewed (6)</summary>

* **onnx/checker.h**: Language not supported
* **onnx/common/ir.h**: Language not supported
* **onnx/common/ir_pb_converter.cc**: Language not supported
* **onnx/defs/attr_proto_util.h**: Language not supported
* **onnx/defs/sequence/defs.cc**: Language not supported
* **onnx/test/cpp/function_verify_test.cc**: Language not supported
</details>

<details>
<summary>Comments suppressed due to low confidence (1)</summary>

**.clang-tidy:52**
* Duplicate entry for 'readability-string-compare' detected. Consider removing one of the duplicate entries to avoid redundant configuration.
```
readability-string-compare,
```
</details>


state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-23T03:43:32Z
user: login: andife
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-23T11:11:00Z

Review comments:
diff_hunk: @@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
path: onnx/checker.h
user: login: andife
body: @justinchuby but the file is called onnx-data_pb.h ... why is the new file name better? If so the filename has also to be renamed?
created_at: 2025-03-22T19:09:20Z
author_association: MEMBER
diff_hunk: @@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
path: onnx/checker.h
user: login: justinchuby
body: Oh that’s right. @cyyever could you share an explanation?
created_at: 2025-03-22T21:07:40Z
author_association: MEMBER
diff_hunk: @@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
path: onnx/checker.h
user: login: cyyever
body: onnx/onnx-data_pb.h includes onnx/onnx-data.pb.h, whose declarations are used in this file.
created_at: 2025-03-23T02:38:29Z
author_association: CONTRIBUTOR
diff_hunk: @@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
path: onnx/checker.h
user: login: cyyever
body: Searching references of "onnx-data_pb.h" in all GitHub projects, I find no one project really uses it and it can be safely removed.
created_at: 2025-03-23T02:54:38Z
author_association: CONTRIBUTOR
diff_hunk: @@ -11,7 +11,7 @@
 #include <utility>
 
 #include "onnx/defs/schema.h"
-#include "onnx/onnx-data_pb.h"
+#include "onnx/onnx-data.pb.h"
path: onnx/checker.h
user: login: justinchuby
body: SG. Thanks!
created_at: 2025-03-23T03:41:48Z
author_association: MEMBER

PR comments:
user: login: codecov[bot]
created_at: 2025-03-22T16:12:16Z
body: ## [Codecov](https://app.codecov.io/gh/onnx/onnx/pull/6832?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onnx) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 56.28%. Comparing base [(`726fe9f`)](https://app.codecov.io/gh/onnx/onnx/commit/726fe9f950830c7a8b2d79899b1146d89b215d38?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onnx) to head [(`69a5c1e`)](https://app.codecov.io/gh/onnx/onnx/commit/69a5c1e352329d8e4d345b740e27a38c3421bd4d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onnx).
> Report is 2 commits behind head on main.

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #6832   +/-   ##
=======================================
  Coverage   56.28%   56.28%           
=======================================
  Files         509      509           
  Lines       32579    32579           
  Branches     3099     3099           
=======================================
  Hits        18336    18336           
  Misses      13385    13385           
  Partials      858      858           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/onnx/onnx/pull/6832?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onnx).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=onnx).

author_association: NONE
user: login: cyyever
created_at: 2025-03-23T07:36:13Z
body: Now that the changes are complete. The next PR will add clang-tidy to linterrunner
author_association: CONTRIBUTOR