From 487942bc22c12cd61a72093586cee182d6c347fa Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Fri, 19 Jul 2024 22:30:34 +0200 Subject: [PATCH] ThrowRangeException with [[noreturn]] --- libsrc/core/exception.hpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/libsrc/core/exception.hpp b/libsrc/core/exception.hpp index ca93b9da..57fbb526 100644 --- a/libsrc/core/exception.hpp +++ b/libsrc/core/exception.hpp @@ -55,8 +55,8 @@ namespace ngcore const char* what() const noexcept override { return m_what.c_str(); } }; - NGCORE_API void ThrowException(const std::string & s); - NGCORE_API void ThrowException(const char * s); + [[noreturn]] NGCORE_API void ThrowException(const std::string & s); + [[noreturn]] NGCORE_API void ThrowException(const char * s); // Out of Range exception class NGCORE_API RangeException : public Exception @@ -84,8 +84,8 @@ namespace ngcore } }; - NGCORE_API void ThrowRangeException(const char * s, int ind, int imin, int imax); - NGCORE_API void ThrowNotTheSameException(const char * s, long int a, long int b); + [[noreturn]] NGCORE_API void ThrowRangeException(const char * s, int ind, int imin, int imax); + [[noreturn]] NGCORE_API void ThrowNotTheSameException(const char * s, long int a, long int b); // Exception used if no simd implementation is available to fall back to standard evaluation @@ -99,21 +99,21 @@ namespace ngcore // Convenience macro to append file name and line of exception origin to the string #define NG_EXCEPTION(s) ngcore::Exception(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t"+std::string(s)) -// template constexpr bool IsSave() { return false; } -template -struct IsSave -{ - constexpr operator bool() const { return false; } -}; +template +struct IsSafe { + constexpr operator bool() const { return false; } }; #if defined(NETGEN_ENABLE_CHECK_RANGE) && !defined(__CUDA_ARCH__) #define NETGEN_CHECK_RANGE(value, min, max_plus_one) \ - { if constexpr (!IsSave()) if ((value)<(min) || (value)>=(max_plus_one)) \ - ThrowRangeException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t", int(value), int(min), int(max_plus_one)); } + { if constexpr (!IsSafe()) { \ + if ((value)<(min) || (value)>=(max_plus_one)) \ + ThrowRangeException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t", int(value), int(min), int(max_plus_one)); } } + // #define NETGEN_CHECK_SHAPE(a,b) \ // { if(a.Shape() != b.Shape()) \ // ngcore::ThrowException(__FILE__ ":" NETGEN_CORE_NGEXEPTION_STR(__LINE__) "\t: shapes don't match"); } + #define NETGEN_CHECK_SAME(a,b) \ { if(a != b) { \ if constexpr(std::is_same() && std::is_same()) \