From d419bbf16f7ad933eabbf0c6ffbaa4cbcaafe377 Mon Sep 17 00:00:00 2001 From: taltenbach <92919739+taltenbach@users.noreply.github.com> Date: Sat, 17 Jan 2026 23:04:52 +0100 Subject: [PATCH] Fix etl::as_bytes for etl::span (#1266) A missing 'const' in the etl::as_bytes implementation was causing a compile-time error when etl::as_bytes was called on a span of const values. Co-authored-by: John Wellbelove --- include/etl/span.h | 2 +- test/test_span_dynamic_extent.cpp | 3 ++- test/test_span_fixed_extent.cpp | 5 +++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 8f57148f..5d03632a 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -1303,7 +1303,7 @@ namespace etl span as_bytes(span s) ETL_NOEXCEPT { - return span(reinterpret_cast(s.data()), s.size_bytes()); + return span(reinterpret_cast(s.data()), s.size_bytes()); } //************************************************************************* diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 7fc1c8c0..586eadcb 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -1325,8 +1325,9 @@ namespace TEST(test_convert_span_any_to_span_byte) { float data[2]{3.141592f, 2.71828f }; + const float const_data[2]{3.141592f, 2.71828f }; - auto const const_bytes = etl::as_bytes(etl::span{data}); + auto const const_bytes = etl::as_bytes(etl::span{const_data}); auto const writable_bytes = etl::as_writable_bytes(etl::span{data}); CHECK_EQUAL(const_bytes.size(), sizeof(data)); diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 137bd9b8..a1825c2c 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -1163,12 +1163,13 @@ namespace TEST(test_convert_span_any_to_span_byte) { float data[2]{3.141592f, 2.71828f}; + const float const_data[2]{3.141592f, 2.71828f}; #if ETL_USING_CPP17 - auto const const_bytes = etl::as_bytes(etl::span{ data }); + auto const const_bytes = etl::as_bytes(etl::span{ const_data }); auto const writable_bytes = etl::as_writable_bytes(etl::span{ data }); #else - auto const const_bytes = etl::as_bytes(etl::span(data)); + auto const const_bytes = etl::as_bytes(etl::span(const_data)); auto const writable_bytes = etl::as_writable_bytes(etl::span(data)); #endif