diff --git a/include/etl/fixed_iterator.h b/include/etl/fixed_iterator.h index f0ab7609..fb274b6c 100644 --- a/include/etl/fixed_iterator.h +++ b/include/etl/fixed_iterator.h @@ -108,7 +108,7 @@ namespace etl //*************************************************************************** /// Dereference operator. //*************************************************************************** - ETL_CONSTEXPR14 typename etl::iterator_traits::value_type operator*() + ETL_CONSTEXPR14 typename etl::iterator_traits::reference operator*() { return *it; } @@ -116,7 +116,7 @@ namespace etl //*************************************************************************** /// Dereference operator. //*************************************************************************** - ETL_CONSTEXPR const typename etl::iterator_traits::value_type operator*() const + ETL_CONSTEXPR typename etl::iterator_traits::reference operator*() const { return *it; } diff --git a/test/test_fixed_iterator.cpp b/test/test_fixed_iterator.cpp index af6d54a1..72b6c907 100644 --- a/test/test_fixed_iterator.cpp +++ b/test/test_fixed_iterator.cpp @@ -229,6 +229,22 @@ namespace CHECK(fi1 != fi3); } + //************************************************************************* + TEST(test_dereference_write_through) + { + int value = 42; + etl::fixed_iterator 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)