From b09a370218c357b70b8b75f524fff3134697dbca Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Tue, 16 Feb 2021 12:41:48 -0800 Subject: [PATCH] Address warning in data_types_internal.h (#6704) Address "unreachable code" warning in data_types_internal.h. --- .../onnxruntime/core/framework/data_types_internal.h | 7 ++++--- onnxruntime/core/framework/tensorprotoutils.cc | 10 ++++++---- onnxruntime/core/session/onnxruntime_c_api.cc | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/onnxruntime/core/framework/data_types_internal.h b/include/onnxruntime/core/framework/data_types_internal.h index 8e1649c552..c1ce7581d2 100644 --- a/include/onnxruntime/core/framework/data_types_internal.h +++ b/include/onnxruntime/core/framework/data_types_internal.h @@ -243,10 +243,11 @@ class CallableDispatchableHelper { } }; -// Default policy is to throw with no return type. +// Default policy is to throw an exception. +// Other policies may set the second result argument accordingly. template struct UnsupportedTypeDefaultPolicy { - Ret operator()(int32_t dt_type) const { + void operator()(int32_t dt_type, Ret& /*result*/) const { ORT_THROW("Unsupported data type: ", dt_type); } }; @@ -264,7 +265,7 @@ class CallableDispatchableRetHelper { Ret Get() { // No type was invoked if (called_ == 0) { - result_ = UnsupportedPolicy()(dt_type_); + UnsupportedPolicy()(dt_type_, result_); } return result_; } diff --git a/onnxruntime/core/framework/tensorprotoutils.cc b/onnxruntime/core/framework/tensorprotoutils.cc index 79a19983ef..015a2da9e1 100644 --- a/onnxruntime/core/framework/tensorprotoutils.cc +++ b/onnxruntime/core/framework/tensorprotoutils.cc @@ -909,8 +909,8 @@ static Status CopySparseData(size_t n_sparse_elements, } struct UnsupportedSparseDataType { - Status operator()(int32_t dt_type) const { - return ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unsupported sparse tensor data type of ", dt_type); + void operator()(int32_t dt_type, Status& status) const { + status = ORT_MAKE_STATUS(ONNXRUNTIME, FAIL, "Unsupported sparse tensor data type of ", dt_type); } }; @@ -998,7 +998,7 @@ common::Status SparseTensorProtoToDenseTensorProto(const ONNX_NAMESPACE::SparseT } else { // No request for std::string - status = UnsupportedSparseDataType()(ONNX_NAMESPACE::TensorProto_DataType_STRING); + UnsupportedSparseDataType()(ONNX_NAMESPACE::TensorProto_DataType_STRING, status); } return status; } @@ -1056,7 +1056,9 @@ common::Status DenseTensorToSparseTensorProto(const ONNX_NAMESPACE::TensorProto& const bool is_string_data = dense_proto.data_type() == ONNX_NAMESPACE::TensorProto_DataType_STRING; if (is_string_data) { - return UnsupportedSparseDataType()(ONNX_NAMESPACE::TensorProto_DataType_STRING); + Status status{}; + UnsupportedSparseDataType()(ONNX_NAMESPACE::TensorProto_DataType_STRING, status); + return status; } const auto data_type = dense_proto.data_type(); diff --git a/onnxruntime/core/session/onnxruntime_c_api.cc b/onnxruntime/core/session/onnxruntime_c_api.cc index 3d72439a58..beb05e20db 100644 --- a/onnxruntime/core/session/onnxruntime_c_api.cc +++ b/onnxruntime/core/session/onnxruntime_c_api.cc @@ -1267,10 +1267,10 @@ struct CallGetValueImpl { // Return status instead of throwing if unsupported type specified struct UnsupportedReturnFailStatus { - ORT_STATUS_PTR operator()(int32_t dt_type) const { + void operator()(int32_t dt_type, OrtStatusPtr& status) const { std::string msg("Unsupported tensor element type in the input: "); msg.append(std::to_string(dt_type)); - return OrtApis::CreateStatus(ORT_FAIL, msg.c_str()); + status = OrtApis::CreateStatus(ORT_FAIL, msg.c_str()); } }; } // namespace c_api_internal