Skip to content

Commit b5e2b1c

Browse files
author
John Wellbelove
committed
Sync with ETL 20.43.2
1 parent a755b13 commit b5e2b1c

File tree

7 files changed

+127
-31
lines changed

7 files changed

+127
-31
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "Embedded Template Library ETL",
3-
"version": "20.43.1",
3+
"version": "20.43.2",
44
"authors": {
55
"name": "John Wellbelove",
66
"email": "[email protected]"

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Embedded Template Library ETL
2-
version=20.43.1
2+
version=20.43.2
33
author= John Wellbelove <[email protected]>
44
maintainer=John Wellbelove <[email protected]>
55
license=MIT

src/etl/array.h

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace etl
116116
//*************************************************************************
117117
ETL_NODISCARD
118118
ETL_CONSTEXPR14
119-
reference at(size_t i)
119+
reference at(size_t i) ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
120120
{
121121
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
122122

@@ -129,7 +129,7 @@ namespace etl
129129
//*************************************************************************
130130
ETL_NODISCARD
131131
ETL_CONSTEXPR14
132-
const_reference at(size_t i) const
132+
const_reference at(size_t i) const ETL_NOEXCEPT_EXPR(ETL_NOT_USING_EXCEPTIONS)
133133
{
134134
ETL_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
135135

@@ -143,8 +143,10 @@ namespace etl
143143
//*************************************************************************
144144
ETL_NODISCARD
145145
ETL_CONSTEXPR14
146-
reference operator[](size_t i)
146+
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));
149+
148150
return _buffer[i];
149151
}
150152

@@ -154,27 +156,38 @@ namespace etl
154156
///\param i The index of the element to access.
155157
//*************************************************************************
156158
ETL_NODISCARD
157-
ETL_CONSTEXPR const_reference operator[](size_t i) const
159+
ETL_CONSTEXPR const_reference operator[](size_t i) const ETL_NOEXCEPT_EXPR(ETL_DEBUG_NOT_USING_EXCEPTIONS)
158160
{
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]);
164+
#else
165+
ETL_DEBUG_ASSERT(i < SIZE, ETL_ERROR(array_out_of_range));
166+
159167
return _buffer[i];
168+
#endif
160169
}
161170

162171
//*************************************************************************
163172
/// Returns a reference to the first element.
164173
//*************************************************************************
165174
ETL_NODISCARD
166175
ETL_CONSTEXPR14
167-
reference front()
176+
reference front() ETL_NOEXCEPT
168177
{
178+
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
179+
169180
return _buffer[0];
170181
}
171182

172183
//*************************************************************************
173184
/// Returns a const reference to the first element.
174185
//*************************************************************************
175186
ETL_NODISCARD
176-
ETL_CONSTEXPR const_reference front() const
187+
ETL_CONSTEXPR const_reference front() const ETL_NOEXCEPT
177188
{
189+
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
190+
178191
return _buffer[0];
179192
}
180193

@@ -183,17 +196,21 @@ namespace etl
183196
//*************************************************************************
184197
ETL_NODISCARD
185198
ETL_CONSTEXPR14
186-
reference back()
199+
reference back() ETL_NOEXCEPT
187200
{
201+
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
202+
188203
return _buffer[SIZE - 1];
189204
}
190205

191206
//*************************************************************************
192207
/// Returns a const reference to the last element.
193208
//*************************************************************************
194209
ETL_NODISCARD
195-
ETL_CONSTEXPR const_reference back() const
210+
ETL_CONSTEXPR const_reference back() const ETL_NOEXCEPT
196211
{
212+
ETL_STATIC_ASSERT(SIZE > 0, "Array is empty.");
213+
197214
return _buffer[SIZE - 1];
198215
}
199216

@@ -429,6 +446,8 @@ namespace etl
429446
//*************************************************************************
430447
inline iterator insert_at(size_t position, parameter_t value)
431448
{
449+
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
450+
432451
return insert(begin() + position, value);
433452
}
434453

@@ -439,6 +458,8 @@ namespace etl
439458
//*************************************************************************
440459
iterator insert(const_iterator position, parameter_t value)
441460
{
461+
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
462+
442463
iterator p = to_iterator(position);
443464

444465
etl::move_backward(p, end() - 1, end());
@@ -456,6 +477,8 @@ namespace etl
456477
template <typename TIterator>
457478
inline iterator insert_at(size_t position, TIterator first, const TIterator last)
458479
{
480+
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
481+
459482
return insert(begin() + position, first, last);
460483
}
461484

@@ -468,6 +491,8 @@ namespace etl
468491
template <typename TIterator>
469492
iterator insert(const_iterator position, TIterator first, const TIterator last)
470493
{
494+
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
495+
471496
iterator p = to_iterator(position);
472497
iterator result(p);
473498

@@ -494,6 +519,8 @@ namespace etl
494519
//*************************************************************************
495520
inline iterator erase_at(size_t position)
496521
{
522+
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
523+
497524
return erase(begin() + position);
498525
}
499526

@@ -504,6 +531,8 @@ namespace etl
504531
//*************************************************************************
505532
iterator erase(const_iterator position)
506533
{
534+
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
535+
507536
iterator p = to_iterator(position);
508537
etl::move(p + 1, end(), p);
509538

@@ -518,6 +547,8 @@ namespace etl
518547
//*************************************************************************
519548
iterator erase_range(size_t first, size_t last)
520549
{
550+
ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
551+
521552
return erase(begin() + first, begin() + last);
522553
}
523554

@@ -529,6 +560,8 @@ namespace etl
529560
//*************************************************************************
530561
iterator erase(const_iterator first, const_iterator last)
531562
{
563+
ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
564+
532565
iterator p = to_iterator(first);
533566
etl::move(last, cend(), p);
534567
return p;
@@ -541,6 +574,8 @@ namespace etl
541574
//*************************************************************************
542575
inline iterator erase_at(size_t position, parameter_t value)
543576
{
577+
ETL_DEBUG_ASSERT(position < SIZE, ETL_ERROR(array_out_of_range));
578+
544579
return erase(begin() + position, value);
545580
}
546581

@@ -551,6 +586,8 @@ namespace etl
551586
//*************************************************************************
552587
iterator erase(const_iterator position, parameter_t value)
553588
{
589+
ETL_DEBUG_ASSERT(cbegin() <= position && position < cend(), ETL_ERROR(array_out_of_range));
590+
554591
iterator p = to_iterator(position);
555592

556593
etl::move(p + 1, end(), p);
@@ -567,16 +604,21 @@ namespace etl
567604
//*************************************************************************
568605
iterator erase_range(size_t first, size_t last, parameter_t value)
569606
{
607+
ETL_DEBUG_ASSERT(first <= last && last <= SIZE, ETL_ERROR(array_out_of_range));
608+
570609
return erase(begin() + first, begin() + last, value);
571610
}
572611

573612
//*************************************************************************
574613
/// Erases a range of values from the array.
575-
///\param position The iterator to the position to erase at.
576-
///\param value The value to use to overwrite the last elements in the array.
614+
///\param first The first item to erase.
615+
///\param last The one past the last item to erase.
616+
///\param value The value to use to overwrite the last elements in the array.
577617
//*************************************************************************
578618
iterator erase(const_iterator first, const_iterator last, parameter_t value)
579619
{
620+
ETL_DEBUG_ASSERT(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(array_out_of_range));
621+
580622
iterator p = to_iterator(first);
581623

582624
p = etl::move(last, cend(), p);

src/etl/error_handler.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,62 @@ namespace etl
364364
#endif
365365
#endif
366366

367+
#if ETL_IS_DEBUG_BUILD
368+
#if defined(ETL_DEBUG_USE_ASSERT_FUNCTION)
369+
#define ETL_DEBUG_ASSERT(b, e) {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));}} // If the condition fails, calls the assert function
370+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;}} // If the condition fails, calls the assert function and return
371+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);}} // If the condition fails, calls the assert function and return a value
372+
373+
#define ETL_DEBUG_ASSERT_FAIL(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e));} // Calls the assert function
374+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return;} // Calls the assert function and return
375+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::private_error_handler::assert_handler<0>::assert_function_ptr((e)); return (v);} // Calls the assert function and return a value
376+
#elif ETL_DEBUG_USING_EXCEPTIONS
377+
#if defined(ETL_DEBUG_LOG_ERRORS)
378+
#define ETL_DEBUG_ASSERT(b, e) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e));}} // If the condition fails, calls the error handler then throws an exception.
379+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE_CPP11_CONSTEXPR(b, e, v) if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e));} return (b) ? (v) : throw(e) // throwing from c++11 constexpr requires ? operator
380+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e)); return;}} // If the condition fails, calls the error handler then throws an exception.
381+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); throw((e)); return(v);}} // If the condition fails, calls the error handler then throws an exception.
382+
383+
#define ETL_DEBUG_ASSERT_FAIL(e) {etl::error_handler::error((e)); throw((e));} // Calls the error handler then throws an exception.
384+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); throw((e)); return;} // Calls the error handler then throws an exception.
385+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); throw((e)); return(v);} // Calls the error handler then throws an exception.
386+
#else
387+
#define ETL_DEBUG_ASSERT(b, e) {if (!(b)) ETL_UNLIKELY {throw((e));}} // If the condition fails, throws an exception.
388+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE_CPP11_CONSTEXPR(b, e, v) return (b) ? (v) : throw(e) // throwing from c++11 constexpr requires ? operator
389+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY {throw((e));}} // If the condition fails, throws an exception.
390+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY {throw((e));}} // If the condition fails, throws an exception.
391+
392+
#define ETL_DEBUG_ASSERT_FAIL(e) {throw((e));} // Throws an exception.
393+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {throw((e));} // Throws an exception.
394+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {throw((e));} // Throws an exception.
395+
#endif
396+
#elif defined(ETL_DEBUG_LOG_ERRORS)
397+
#define ETL_DEBUG_ASSERT(b, e) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e));}} // If the condition fails, calls the error handler
398+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); return;}} // If the condition fails, calls the error handler and return
399+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY {etl::error_handler::error((e)); return (v);}} // If the condition fails, calls the error handler and return a value
400+
401+
#define ETL_DEBUG_ASSERT_FAIL(e) {etl::error_handler::error((e));} // Calls the error handler
402+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {etl::error_handler::error((e)); return;} // Calls the error handler and return
403+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {etl::error_handler::error((e)); return (v);} // Calls the error handler and return a value
404+
#else
405+
#define ETL_DEBUG_ASSERT(b, e) assert((b)) // If the condition fails, asserts.
406+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY {assert(false); return;}} // If the condition fails, asserts and return.
407+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY {assert(false); return(v);}} // If the condition fails, asserts and return a value.
408+
409+
#define ETL_DEBUG_ASSERT_FAIL(e) assert(false) // Asserts.
410+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {assert(false); return;} // Asserts.
411+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {assert(false); return(v);} // Asserts.
412+
#endif
413+
#else
414+
#define ETL_DEBUG_ASSERT(b, e) // Does nothing.
415+
#define ETL_DEBUG_ASSERT_OR_RETURN(b, e) {if (!(b)) ETL_UNLIKELY return;} // Returns.
416+
#define ETL_DEBUG_ASSERT_OR_RETURN_VALUE(b, e, v) {if (!(b)) ETL_UNLIKELY return(v);} // Returns a value.
417+
418+
#define ETL_DEBUG_ASSERT_FAIL(e) // Does nothing.
419+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN(e) {return;} // Returns.
420+
#define ETL_DEBUG_ASSERT_FAIL_AND_RETURN_VALUE(e, v) {return(v);} // Returns a value.
421+
#endif
422+
367423
#if defined(ETL_VERBOSE_ERRORS)
368424
#define ETL_ERROR(e) (e(__FILE__, __LINE__)) // Make an exception with the file name and line number.
369425
#define ETL_ERROR_WITH_VALUE(e, v) (e(__FILE__, __LINE__, (v))) // Make an exception with the file name, line number and value.

src/etl/expected.h

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -675,9 +675,7 @@ namespace etl
675675
//*******************************************
676676
value_type* operator ->()
677677
{
678-
#if ETL_IS_DEBUG_BUILD
679-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
680-
#endif
678+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
681679

682680
return etl::addressof(etl::get<value_type>(storage));
683681
}
@@ -687,9 +685,7 @@ namespace etl
687685
//*******************************************
688686
const value_type* operator ->() const
689687
{
690-
#if ETL_IS_DEBUG_BUILD
691-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
692-
#endif
688+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
693689

694690
return etl::addressof(etl::get<value_type>(storage));
695691
}
@@ -699,9 +695,7 @@ namespace etl
699695
//*******************************************
700696
value_type& operator *() ETL_LVALUE_REF_QUALIFIER
701697
{
702-
#if ETL_IS_DEBUG_BUILD
703-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
704-
#endif
698+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
705699

706700
return etl::get<value_type>(storage);
707701
}
@@ -711,9 +705,7 @@ namespace etl
711705
//*******************************************
712706
const value_type& operator *() const ETL_LVALUE_REF_QUALIFIER
713707
{
714-
#if ETL_IS_DEBUG_BUILD
715-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
716-
#endif
708+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
717709

718710
return etl::get<value_type>(storage);
719711
}
@@ -724,9 +716,7 @@ namespace etl
724716
//*******************************************
725717
value_type&& operator *()&&
726718
{
727-
#if ETL_IS_DEBUG_BUILD
728-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
729-
#endif
719+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
730720

731721
return etl::move(etl::get<value_type>(storage));
732722
}
@@ -736,9 +726,7 @@ namespace etl
736726
//*******************************************
737727
const value_type&& operator *() const&&
738728
{
739-
#if ETL_IS_DEBUG_BUILD
740-
ETL_ASSERT(has_value(), ETL_ERROR(expected_invalid));
741-
#endif
729+
ETL_DEBUG_ASSERT(has_value(), ETL_ERROR(expected_invalid));
742730

743731
return etl::move(etl::get<value_type>(storage));
744732
}

src/etl/platform.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ SOFTWARE.
251251
#define ETL_NOT_USING_EXCEPTIONS 1
252252
#endif
253253

254+
//*************************************
255+
// Indicate if C++ exceptions are enabled for debug asserts.
256+
#if ETL_IS_DEBUG_BUILD && defined(ETL_DEBUG_THROW_EXCEPTIONS)
257+
#define ETL_DEBUG_USING_EXCEPTIONS 1
258+
#define ETL_DEBUG_NOT_USING_EXCEPTIONS 0
259+
#else
260+
#define ETL_DEBUG_USING_EXCEPTIONS 0
261+
#define ETL_DEBUG_NOT_USING_EXCEPTIONS 1
262+
#endif
263+
254264
//*************************************
255265
// Indicate if nullptr is used.
256266
#if ETL_NO_NULLPTR_SUPPORT

src/etl/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ SOFTWARE.
4040

4141
#define ETL_VERSION_MAJOR 20
4242
#define ETL_VERSION_MINOR 43
43-
#define ETL_VERSION_PATCH 1
43+
#define ETL_VERSION_PATCH 2
4444

4545
#define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH)
4646
#define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH)

0 commit comments

Comments
 (0)