diff --git a/include/etl/array_wrapper.h b/include/etl/array_wrapper.h index 96322323..8617a4f7 100644 --- a/include/etl/array_wrapper.h +++ b/include/etl/array_wrapper.h @@ -280,7 +280,7 @@ namespace etl /// Returns a const reference to the indexed value. /// If asserts or exceptions are enabled, throws an etl::array_wrapper_bounds if the index is out of bounds. //************************************************************************* - ETL_CONSTEXPR_INDEX_OPERATOR const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR + ETL_CONSTEXPR_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR { ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(etl::array_wrapper_bounds)); return ARRAY_[i]; diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index 0b2c87c2..06d52c5b 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -364,6 +364,16 @@ namespace etl #endif #endif +//************************************* +// ETL_CONSTEXPR_INDEX_OPERATOR: constexpr if asserts are no-ops, constexpr14 when they contain statements. +#if defined(ETL_NO_CHECKS) + #define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR +#elif defined(ETL_USE_ASSERT_FUNCTION) || ETL_USING_EXCEPTIONS || defined(ETL_LOG_ERRORS) || ETL_IS_DEBUG_BUILD + #define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR14 +#else + #define ETL_CONSTEXPR_OR_ASSERT ETL_CONSTEXPR +#endif + //************************************* #if defined(ETL_CHECK_PUSH_POP) #define ETL_ASSERT_CHECK_PUSH_POP(b, e) ETL_ASSERT(b, e) @@ -379,13 +389,11 @@ namespace etl #define ETL_NOT_CHECKING_INDEX_OPERATOR 0 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) ETL_ASSERT(b,e) #define ETL_NOEXCEPT_INDEX_OPERATOR - #define ETL_CONSTEXPR_INDEX_OPERATOR ETL_CONSTEXPR14 #else #define ETL_CHECKING_INDEX_OPERATOR 0 #define ETL_NOT_CHECKING_INDEX_OPERATOR 1 #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) #define ETL_NOEXCEPT_INDEX_OPERATOR ETL_NOEXCEPT - #define ETL_CONSTEXPR_INDEX_OPERATOR ETL_CONSTEXPR #endif //************************************* @@ -393,12 +401,10 @@ namespace etl #define ETL_CHECKING_EXTRA 1 #define ETL_NOT_CHECKING_EXTRA 0 #define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b,e) - #define ETL_CONSTEXPR_CHECK_EXTRA ETL_CONSTEXPR14 #else #define ETL_CHECKING_EXTRA 0 #define ETL_NOT_CHECKING_EXTRA 1 #define ETL_ASSERT_CHECK_EXTRA(b, e) - #define ETL_CONSTEXPR_CHECK_EXTRA ETL_CONSTEXPR #endif //************************************* diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 1a9c9af9..d6a6dbf0 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -191,7 +191,7 @@ namespace etl /// Returns a const reference to the first element. /// If asserts or exceptions are enabled, throws an etl::string_view_empty if the view is empty. //************************************************************************* - ETL_CONSTEXPR_CHECK_EXTRA const_reference front() const + ETL_CONSTEXPR_OR_ASSERT const_reference front() const { ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty)); return *mbegin; @@ -201,7 +201,7 @@ namespace etl /// Returns a const reference to the last element. /// If asserts or exceptions are enabled, throws an etl::string_view_empty if the view is empty. //************************************************************************* - ETL_CONSTEXPR_CHECK_EXTRA const_reference back() const + ETL_CONSTEXPR_OR_ASSERT const_reference back() const { ETL_ASSERT_CHECK_EXTRA(!empty(), ETL_ERROR(string_view_empty)); return *(mend - 1); @@ -347,7 +347,7 @@ namespace etl /// Returns a const reference to the indexed value. /// If asserts or exceptions are enabled, throws an etl::string_view_bounds if the index is out of bounds. //************************************************************************* - ETL_CONSTEXPR_INDEX_OPERATOR const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR + ETL_CONSTEXPR_OR_ASSERT const_reference operator[](size_t i) const ETL_NOEXCEPT_INDEX_OPERATOR { ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_view_bounds)); return mbegin[i];