Fix fixed_iterator::operator* return type

fixed_iterator::operator* returned value_type by value, so writes like *it = ...
modified a temporary rather than the underlying location. This broke the
iterator’s intended use (e.g., writing to a fixed register/memory location).
Now returning iterator_traits<TIterator>::reference instead (const and
non-const overloads).
This commit is contained in:
Roland Reichwein 2026-05-31 14:00:51 +02:00
parent 01ed29f817
commit 288587070c
2 changed files with 18 additions and 2 deletions

View File

@ -108,7 +108,7 @@ namespace etl
//***************************************************************************
/// Dereference operator.
//***************************************************************************
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::value_type operator*()
ETL_CONSTEXPR14 typename etl::iterator_traits<TIterator>::reference operator*()
{
return *it;
}
@ -116,7 +116,7 @@ namespace etl
//***************************************************************************
/// Dereference operator.
//***************************************************************************
ETL_CONSTEXPR const typename etl::iterator_traits<TIterator>::value_type operator*() const
ETL_CONSTEXPR typename etl::iterator_traits<TIterator>::reference operator*() const
{
return *it;
}

View File

@ -229,6 +229,22 @@ namespace
CHECK(fi1 != fi3);
}
//*************************************************************************
TEST(test_dereference_write_through)
{
int value = 42;
etl::fixed_iterator<int*> fi(&value);
// Writing through the dereferenced iterator should modify the underlying value.
*fi = 99;
CHECK_EQUAL(99, value);
// Increment does nothing, so writing again still targets the same location.
++fi;
*fi = 123;
CHECK_EQUAL(123, value);
}
#if ETL_USING_CPP14
//*************************************************************************
TEST(test_fixed_iterator_constexpr_ctor)