diff --git a/lib/cpp/src/thrift/numeric_cast.h b/lib/cpp/src/thrift/numeric_cast.h deleted file mode 100644 index d7063dbc690..00000000000 --- a/lib/cpp/src/thrift/numeric_cast.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef THRIFT_NUMERIC_CAST_H -#define THRIFT_NUMERIC_CAST_H - -#include -#include - -#if defined(_MSC_VER) -// avoid compiler warnings and errors in MSVC if max is defined as a macro -#undef max -#endif - -namespace apache { -namespace thrift { - -/** - * @brief Perform a safe numeric cast - * - * Previously this was provided by `boost::numeric_cast`. This - * implementation reduces the dependency on `boost`. - * - * @tparam Dst The destination type - * @tparam Src The source type - * @param value The value to be converted - * @return Dst The converted value - * - * @see SA49658182 - */ -template -inline Dst numeric_cast(Src value) { - typedef std::numeric_limits DstLim; - typedef std::numeric_limits SrcLim; - - const bool positive_overflow_possible = DstLim::max() < SrcLim::max(); - const bool negative_overflow_possible = DstLim::lowest() > SrcLim::lowest(); - - if (positive_overflow_possible && value > DstLim::max()) { - throw std::bad_cast(); - } - - if (negative_overflow_possible && (value < DstLim::lowest())) { - throw std::bad_cast(); - } - - // limits have been checked, therefore safe to cast - return static_cast(value); -} - -} // namespace thrift -} // namespace apache - -#endif diff --git a/lib/cpp/src/thrift/transport/TTransportException.h b/lib/cpp/src/thrift/transport/TTransportException.h index 3ce55cb765b..dd5f361f151 100644 --- a/lib/cpp/src/thrift/transport/TTransportException.h +++ b/lib/cpp/src/thrift/transport/TTransportException.h @@ -20,9 +20,8 @@ #ifndef _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ #define _THRIFT_TRANSPORT_TTRANSPORTEXCEPTION_H_ 1 +#include #include - -#include #include namespace apache { @@ -93,7 +92,7 @@ class TTransportException : public apache::thrift::TException { */ template To safe_numeric_cast(From i) { try { - return apache::thrift::numeric_cast(i); + return boost::numeric_cast(i); } catch (const std::bad_cast& bc) { throw TTransportException(TTransportException::CORRUPTED_DATA,