diff --git a/include/etl/array.h b/include/etl/array.h index fbf5063a..a238269e 100644 --- a/include/etl/array.h +++ b/include/etl/array.h @@ -145,7 +145,7 @@ namespace etl ETL_CONSTEXPR14 reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_DEBUG_NOT_USING_EXCEPTIONS) { - ETL_DEBUG_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range)); return _buffer[i]; } @@ -158,11 +158,11 @@ namespace etl ETL_NODISCARD ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_DEBUG_NOT_USING_EXCEPTIONS) { - //throwing from c++11 constexpr requires a special macro -#if ETL_USING_CPP11 && !ETL_USING_CPP14 && ETL_DEBUG_USING_EXCEPTIONS - ETL_DEBUG_ASSERT_OR_RETURN_VALUE_CPP11_CONSTEXPR(i < SIZE, ETL_ERROR(array_out_of_range), _buffer[i]); + // Throwing from c++11 constexpr requires special syntax +#if ETL_USING_CPP11 && !ETL_USING_CPP14 && ETL_USING_EXCEPTIONS && defined(ETL_CHECK_INDEX_OPERATOR) + return i < SIZE ? _buffer[i] : throw(ETL_ERROR(array_out_of_range)); #else - ETL_DEBUG_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range)); return _buffer[i]; #endif @@ -446,7 +446,7 @@ namespace etl //************************************************************************* inline iterator insert_at(size_t position, parameter_t value) { - ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range)); return insert(begin() + position, value); } @@ -458,7 +458,7 @@ namespace etl //************************************************************************* iterator insert(const_iterator position, parameter_t value) { - ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(position); @@ -477,7 +477,7 @@ namespace etl template inline iterator insert_at(size_t position, TIterator first, const TIterator last) { - ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range)); return insert(begin() + position, first, last); } @@ -491,7 +491,7 @@ namespace etl template iterator insert(const_iterator position, TIterator first, const TIterator last) { - ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(position); iterator result(p); @@ -519,7 +519,7 @@ namespace etl //************************************************************************* inline iterator erase_at(size_t position) { - ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range)); return erase(begin() + position); } @@ -531,7 +531,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator position) { - ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(position); etl::move(p + 1, end(), p); @@ -547,7 +547,7 @@ namespace etl //************************************************************************* iterator erase_range(size_t first, size_t last) { - ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range)); return erase(begin() + first, begin() + last); } @@ -560,7 +560,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator first, const_iterator last) { - ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(first); etl::move(last, cend(), p); @@ -574,7 +574,7 @@ namespace etl //************************************************************************* inline iterator erase_at(size_t position, parameter_t value) { - ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range)); return erase(begin() + position, value); } @@ -586,7 +586,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator position, parameter_t value) { - ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(position); @@ -604,8 +604,8 @@ namespace etl //************************************************************************* iterator erase_range(size_t first, size_t last, parameter_t value) { - ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range)); - + ETL_ASSERT_CHECK_EXTRA(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range)); + return erase(begin() + first, begin() + last, value); } @@ -617,7 +617,7 @@ namespace etl //************************************************************************* iterator erase(const_iterator first, const_iterator last, parameter_t value) { - ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range)); + ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range)); iterator p = to_iterator(first); diff --git a/include/etl/error_handler.h b/include/etl/error_handler.h index a6586250..2a2c2d89 100644 --- a/include/etl/error_handler.h +++ b/include/etl/error_handler.h @@ -436,6 +436,13 @@ namespace etl #define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e) #endif +//************************************* +#ifdef ETL_CHECK_EXTRA + #define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b,e) +#else + #define ETL_ASSERT_CHECK_EXTRA(b, e) +#endif + //************************************* #if defined(ETL_VERBOSE_ERRORS) #define ETL_ERROR(e) (e(__FILE__, __LINE__)) // Make an exception with the file name and line number. diff --git a/test/etl_profile.h b/test/etl_profile.h index d98f6141..a7c680ff 100644 --- a/test/etl_profile.h +++ b/test/etl_profile.h @@ -35,6 +35,8 @@ SOFTWARE. #define ETL_DEBUG_THROW_EXCEPTIONS #define ETL_VERBOSE_ERRORS #define ETL_CHECK_PUSH_POP +#define ETL_CHECK_INDEX_OPERATOR +#define ETL_CHECK_EXTRA #define ETL_ISTRING_REPAIR_ENABLE #define ETL_IVECTOR_REPAIR_ENABLE #define ETL_IDEQUE_REPAIR_ENABLE diff --git a/test/test_array.cpp b/test/test_array.cpp index c779ab76..857719f2 100644 --- a/test/test_array.cpp +++ b/test/test_array.cpp @@ -135,7 +135,6 @@ namespace CHECK_EQUAL(data[i], compare_data[i]); } - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range); } @@ -149,7 +148,6 @@ namespace CHECK_EQUAL(data[i], compare_data[i]); } - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range); } @@ -451,7 +449,6 @@ namespace CHECK(isEqual); // Insert out of range - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined CHECK_THROW({ result = data.insert_at(data.size(), 99); }, etl::array_out_of_range); } @@ -505,7 +502,6 @@ namespace CHECK(isEqual); // Insert out of range - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined CHECK_THROW({ result = data.insert_at(data.size(), &source2[0], &source2[13]); }, etl::array_out_of_range); } @@ -563,7 +559,6 @@ namespace CHECK(isEqual); // Erase out of range - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined CHECK_THROW({ result = data.erase_at(data.size()); }, etl::array_out_of_range); } @@ -620,7 +615,6 @@ namespace isEqual = std::equal(data.begin(), data.end(), std::begin(check3b)); CHECK(isEqual); - //ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined // first is greater than last CHECK_THROW({ result = data.erase_range(6, 5, 99); }, etl::array_out_of_range);