Merge pull request #25899 from vrabaud:move_no_except

Mark cv::Mat(Mat&&) as noexcept #25899

This fixes https://github.com/opencv/opencv/issues/25065

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
pull/25903/head
Vincent Rabaud 4 months ago committed by GitHub
parent 78195bc3df
commit 3ff97c5580
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 18
      modules/core/include/opencv2/core/base.hpp
  2. 2
      modules/core/include/opencv2/core/mat.hpp
  3. 2
      modules/core/src/matrix.cpp
  4. 6
      modules/core/src/system.cpp

@ -297,6 +297,21 @@ It is possible to alternate error processing by using redirectError().
*/ */
CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line); CV_EXPORTS CV_NORETURN void error(int _code, const String& _err, const char* _func, const char* _file, int _line);
/*! @brief Signals an error and terminate application.
By default the function prints information about the error to stderr, then it terminates application
with std::terminate. The function is designed for invariants check in functions and methods with
noexcept attribute.
@param _code - error code (Error::Code)
@param _err - error description
@param _func - function name. Available only when the compiler supports getting it
@param _file - source file name where the error has occurred
@param _line - line number in the source file where the error has occurred
@see CV_AssertTerminate
*/
CV_EXPORTS CV_NORETURN void terminate(int _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT;
#ifdef CV_STATIC_ANALYSIS #ifdef CV_STATIC_ANALYSIS
// In practice, some macro are not processed correctly (noreturn is not detected). // In practice, some macro are not processed correctly (noreturn is not detected).
@ -338,8 +353,11 @@ for example:
The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros The macros CV_Assert (and CV_DbgAssert(expr)) evaluate the specified expression. If it is 0, the macros
raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release raise an error (see cv::error). The macro CV_Assert checks the condition in both Debug and Release
configurations while CV_DbgAssert is only retained in the Debug configuration. configurations while CV_DbgAssert is only retained in the Debug configuration.
CV_AssertTerminate is analog of CV_Assert for invariants check in functions with noexcept attribute.
It does not throw exception, but terminates the application.
*/ */
#define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0) #define CV_Assert( expr ) do { if(!!(expr)) ; else cv::error( cv::Error::StsAssert, #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#define CV_AssertTerminate( expr ) do { if(!!(expr)) ; else cv::terminate( #expr, CV_Func, __FILE__, __LINE__ ); } while(0)
#endif // CV_STATIC_ANALYSIS #endif // CV_STATIC_ANALYSIS

@ -2119,7 +2119,7 @@ public:
/** @overload */ /** @overload */
template<typename _Tp, typename Functor> void forEach(const Functor& operation) const; template<typename _Tp, typename Functor> void forEach(const Functor& operation) const;
Mat(Mat&& m); Mat(Mat&& m) CV_NOEXCEPT;
Mat& operator = (Mat&& m); Mat& operator = (Mat&& m);
enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG }; enum { MAGIC_VAL = 0x42FF0000, AUTO_STEP = 0, CONTINUOUS_FLAG = CV_MAT_CONT_FLAG, SUBMATRIX_FLAG = CV_SUBMAT_FLAG };

@ -595,7 +595,7 @@ size_t Mat::total(int startDim, int endDim) const
} }
Mat::Mat(Mat&& m) Mat::Mat(Mat&& m) CV_NOEXCEPT
: flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data), : flags(m.flags), dims(m.dims), rows(m.rows), cols(m.cols), data(m.data),
datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator), datastart(m.datastart), dataend(m.dataend), datalimit(m.datalimit), allocator(m.allocator),
u(m.u), size(&rows) u(m.u), size(&rows)

@ -1316,6 +1316,12 @@ redirectError( ErrorCallback errCallback, void* userdata, void** prevUserdata)
return prevCallback; return prevCallback;
} }
void terminate(int _code, const String& _err, const char* _func, const char* _file, int _line) CV_NOEXCEPT
{
dumpException(cv::Exception(_code, _err, _func, _file, _line));
std::terminate();
}
} }
CV_IMPL int cvCheckHardwareSupport(int feature) CV_IMPL int cvCheckHardwareSupport(int feature)

Loading…
Cancel
Save