mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
etl array checks (#1188)
* Regression fix: Support zero arguments emplace() in etl::optional (#1183) * Added coderabbitai configuration * Added builtin mem function tests * Modified etl::typed_storage * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Added ETL_NOEXCEPT and ETL_NOEXCEPT_IF_NO_THROW * Added etl::typed_storage_ext and swap for same * Added etl::typed_storage_ext and swap for same # Conflicts: # include/etl/alignment.h * Added release notes * Fixes to GCC -O2 errors * Changed char* parameters to value_type* parameters * Fixed compilation issues for const containers unit tests * Added automatic selection of __builtin_memxxx functions for GCC and clang * Added enhanced coderabbit configuration * Updated version and release notes * Disabled constexpr const container tests for C++11 * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Updated version and release notes * feat: removed unreachable break statements (#1169) * Updated version and release notes * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Support zero arguments emplace() in etl::optional For non-fundamental types, a recent change in etl::optional was introduced that doesn't support zero arguments emplace() anymore. This change fixes it and adds the respective test. --------- Co-authored-by: John Wellbelove <john.wellbelove@asterconsulting.co.uk> Co-authored-by: Drew Rife <darife@jlg.com> * Fix etl::typed_storage by supporting omitted destructors (#1182) * Added coderabbitai configuration * Added builtin mem function tests * Modified etl::typed_storage * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Added ETL_NOEXCEPT and ETL_NOEXCEPT_IF_NO_THROW * Added etl::typed_storage_ext and swap for same * Added etl::typed_storage_ext and swap for same # Conflicts: # include/etl/alignment.h * Added release notes * Fixes to GCC -O2 errors * Changed char* parameters to value_type* parameters * Fixed compilation issues for const containers unit tests * Added automatic selection of __builtin_memxxx functions for GCC and clang * Added enhanced coderabbit configuration * Updated version and release notes * Disabled constexpr const container tests for C++11 * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Attempted fixes for MacOS compilation * Updated version and release notes * feat: removed unreachable break statements (#1169) * Updated version and release notes * Modified etl::typed_storage # Conflicts: # include/etl/alignment.h * Fix etl::typed_storage by supporting omitted destructors In a recent change to alignment.h, the etl::typed_storage was changed in a way that in case of an already constructed object, the object is created via assignment. However, this contradicts the original use case that led to etl::typed_storage in the first place: https://github.com/ETLCPP/etl/pull/1023 The goal is to omit destructors (and at the same time support classes with deleted assignment operators), so they can be optimized out at link time. This change reverts commit ac7b268 to restore the original functionality and changes the test to reflect the original use case. * Fix missing create() in non-C++11 typed_storage_ext constructor * Typo fix --------- Co-authored-by: John Wellbelove <john.wellbelove@asterconsulting.co.uk> Co-authored-by: Drew Rife <darife@jlg.com> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> * removed navis file from project * Updated version and release notes * Removed forced unsigned int cast in type_def bit-shift operators (#1178) * Removed UB in type_def bit-shift operators * Changed shift operators to allow both signed and unsigned operands for shifts This allows the library user to explicitly use unsigned values to avoid UB * Fixed constexpr errors for CPP11 * Changed is_arithmetic checks to use is_integral since valid shifts require integral operands * Removed need for CPP11 since changes are CPP03 compatible * Delete project navis files * Add force CI check on piull requests * Removed ETL_NOEXCEPT from delegate operator(), call_if(), and call_or() Removed ETL_NOEXCEPT from closureoperator(), call_if(), and call_or() * Updated version and release notes * Updated version and release notes * Remove noexcept from delegate method stubs. (#1185) In addition to removing noexcept from call_if, this is also needed to prevent an abort when cancelling a pthread that is executing a delegate. * Updated version and release notes * Re architect the extra checks * Add CHECK_EXTRA * Fix newline at end of file * The check index macro also needs to be defined to throw * Remove ETL_VERBOSE_ERRORS macros --------- Co-authored-by: Roland Reichwein <Roland.Reichwein@bmw.de> Co-authored-by: John Wellbelove <john.wellbelove@asterconsulting.co.uk> Co-authored-by: Drew Rife <darife@jlg.com> Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com> Co-authored-by: David Ockey <2897027+ockeydockey@users.noreply.github.com> Co-authored-by: Marco Nilsson <marco@zyax.se>
This commit is contained in:
parent
e88a74362b
commit
3295cb30ca
@ -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 <typename TIterator>
|
||||
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 <typename TIterator>
|
||||
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);
|
||||
|
||||
|
||||
@ -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.
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user