Skip to content

Commit 4cf522e

Browse files
mike919192rolandreichweinbmwJohn Wellbelovedrewr95jwellbelove
committed
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 <[email protected]> Co-authored-by: Drew Rife <[email protected]> * 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: #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 <[email protected]> Co-authored-by: Drew Rife <[email protected]> Co-authored-by: John Wellbelove <[email protected]> * 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 <[email protected]> Co-authored-by: John Wellbelove <[email protected]> Co-authored-by: Drew Rife <[email protected]> Co-authored-by: John Wellbelove <[email protected]> Co-authored-by: David Ockey <[email protected]> Co-authored-by: Marco Nilsson <[email protected]>
1 parent 69c3f74 commit 4cf522e

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

include/etl/array.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ namespace etl
145145
ETL_CONSTEXPR14
146146
reference operator[](size_t i) ETL_NOEXCEPT_EXPR(ETL_DEBUG_NOT_USING_EXCEPTIONS)
147147
{
148-
ETL_DEBUG_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
148+
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range));
149149

150150
return _buffer[i];
151151
}
@@ -158,11 +158,11 @@ namespace etl
158158
ETL_NODISCARD
159159
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_DEBUG_NOT_USING_EXCEPTIONS)
160160
{
161-
//throwing from c++11 constexpr requires a special macro
162-
#if ETL_USING_CPP11 && !ETL_USING_CPP14 && ETL_DEBUG_USING_EXCEPTIONS
163-
ETL_DEBUG_ASSERT_OR_RETURN_VALUE_CPP11_CONSTEXPR(i < SIZE, ETL_ERROR(array_out_of_range), _buffer[i]);
161+
// Throwing from c++11 constexpr requires special syntax
162+
#if ETL_USING_CPP11 && !ETL_USING_CPP14 && ETL_USING_EXCEPTIONS && defined(ETL_CHECK_INDEX_OPERATOR)
163+
return i < SIZE ? _buffer[i] : throw(ETL_ERROR(array_out_of_range));
164164
#else
165-
ETL_DEBUG_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
165+
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < SIZE, ETL_ERROR(array_out_of_range));
166166

167167
return _buffer[i];
168168
#endif
@@ -446,7 +446,7 @@ namespace etl
446446
//*************************************************************************
447447
inline iterator insert_at(size_t position, parameter_t value)
448448
{
449-
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
449+
ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range));
450450

451451
return insert(begin() + position, value);
452452
}
@@ -458,7 +458,7 @@ namespace etl
458458
//*************************************************************************
459459
iterator insert(const_iterator position, parameter_t value)
460460
{
461-
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
461+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
462462

463463
iterator p = to_iterator(position);
464464

@@ -477,7 +477,7 @@ namespace etl
477477
template <typename TIterator>
478478
inline iterator insert_at(size_t position, TIterator first, const TIterator last)
479479
{
480-
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
480+
ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range));
481481

482482
return insert(begin() + position, first, last);
483483
}
@@ -491,7 +491,7 @@ namespace etl
491491
template <typename TIterator>
492492
iterator insert(const_iterator position, TIterator first, const TIterator last)
493493
{
494-
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
494+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
495495

496496
iterator p = to_iterator(position);
497497
iterator result(p);
@@ -519,7 +519,7 @@ namespace etl
519519
//*************************************************************************
520520
inline iterator erase_at(size_t position)
521521
{
522-
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
522+
ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range));
523523

524524
return erase(begin() + position);
525525
}
@@ -531,7 +531,7 @@ namespace etl
531531
//*************************************************************************
532532
iterator erase(const_iterator position)
533533
{
534-
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
534+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
535535

536536
iterator p = to_iterator(position);
537537
etl::move(p + 1, end(), p);
@@ -547,7 +547,7 @@ namespace etl
547547
//*************************************************************************
548548
iterator erase_range(size_t first, size_t last)
549549
{
550-
ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
550+
ETL_ASSERT_CHECK_EXTRA(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
551551

552552
return erase(begin() + first, begin() + last);
553553
}
@@ -560,7 +560,7 @@ namespace etl
560560
//*************************************************************************
561561
iterator erase(const_iterator first, const_iterator last)
562562
{
563-
ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
563+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
564564

565565
iterator p = to_iterator(first);
566566
etl::move(last, cend(), p);
@@ -574,7 +574,7 @@ namespace etl
574574
//*************************************************************************
575575
inline iterator erase_at(size_t position, parameter_t value)
576576
{
577-
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
577+
ETL_ASSERT_CHECK_EXTRA(position < SIZE, ETL_ERROR(array_out_of_range));
578578

579579
return erase(begin() + position, value);
580580
}
@@ -586,7 +586,7 @@ namespace etl
586586
//*************************************************************************
587587
iterator erase(const_iterator position, parameter_t value)
588588
{
589-
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
589+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
590590

591591
iterator p = to_iterator(position);
592592

@@ -604,8 +604,8 @@ namespace etl
604604
//*************************************************************************
605605
iterator erase_range(size_t first, size_t last, parameter_t value)
606606
{
607-
ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
608-
607+
ETL_ASSERT_CHECK_EXTRA(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
608+
609609
return erase(begin() + first, begin() + last, value);
610610
}
611611

@@ -617,7 +617,7 @@ namespace etl
617617
//*************************************************************************
618618
iterator erase(const_iterator first, const_iterator last, parameter_t value)
619619
{
620-
ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
620+
ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
621621

622622
iterator p = to_iterator(first);
623623

include/etl/error_handler.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,13 @@ namespace etl
436436
#define ETL_ASSERT_CHECK_INDEX_OPERATOR(b, e)
437437
#endif
438438

439+
//*************************************
440+
#ifdef ETL_CHECK_EXTRA
441+
#define ETL_ASSERT_CHECK_EXTRA(b, e) ETL_ASSERT(b,e)
442+
#else
443+
#define ETL_ASSERT_CHECK_EXTRA(b, e)
444+
#endif
445+
439446
//*************************************
440447
#if defined(ETL_VERBOSE_ERRORS)
441448
#define ETL_ERROR(e) (e(__FILE__, __LINE__)) // Make an exception with the file name and line number.

test/etl_profile.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ SOFTWARE.
3535
#define ETL_DEBUG_THROW_EXCEPTIONS
3636
#define ETL_VERBOSE_ERRORS
3737
#define ETL_CHECK_PUSH_POP
38+
#define ETL_CHECK_INDEX_OPERATOR
39+
#define ETL_CHECK_EXTRA
3840
#define ETL_ISTRING_REPAIR_ENABLE
3941
#define ETL_IVECTOR_REPAIR_ENABLE
4042
#define ETL_IDEQUE_REPAIR_ENABLE

test/test_array.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ namespace
135135
CHECK_EQUAL(data[i], compare_data[i]);
136136
}
137137

138-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
139138
CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range);
140139
}
141140

@@ -149,7 +148,6 @@ namespace
149148
CHECK_EQUAL(data[i], compare_data[i]);
150149
}
151150

152-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
153151
CHECK_THROW({ int d = data[data.size()]; (void)d; }, etl::array_out_of_range);
154152
}
155153

@@ -451,7 +449,6 @@ namespace
451449
CHECK(isEqual);
452450

453451
// Insert out of range
454-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
455452
CHECK_THROW({ result = data.insert_at(data.size(), 99); }, etl::array_out_of_range);
456453
}
457454

@@ -505,7 +502,6 @@ namespace
505502
CHECK(isEqual);
506503

507504
// Insert out of range
508-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
509505
CHECK_THROW({ result = data.insert_at(data.size(), &source2[0], &source2[13]); }, etl::array_out_of_range);
510506
}
511507

@@ -563,7 +559,6 @@ namespace
563559
CHECK(isEqual);
564560

565561
// Erase out of range
566-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
567562
CHECK_THROW({ result = data.erase_at(data.size()); }, etl::array_out_of_range);
568563
}
569564

@@ -620,7 +615,6 @@ namespace
620615
isEqual = std::equal(data.begin(), data.end(), std::begin(check3b));
621616
CHECK(isEqual);
622617

623-
//ETL_DEBUG and ETL_THROW_EXCEPTIONS are defined
624618
// first is greater than last
625619
CHECK_THROW({ result = data.erase_range(6, 5, 99); }, etl::array_out_of_range);
626620

0 commit comments

Comments
 (0)