diff --git a/include/etl/span.h b/include/etl/span.h index 1c40d4f1f..0bd3f1c1b 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -354,6 +354,12 @@ namespace etl template etl::span subspan() const { + //if extent is static, check that OFFSET is within the original span + ETL_STATIC_ASSERT((extent != etl::dynamic_extent) ? OFFSET <= extent : true, "OFFSET is not within the original span"); + + //if count is also static, check that OFFSET + COUNT is within the original span + ETL_STATIC_ASSERT((extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); + if (COUNT == etl::dynamic_extent) { return etl::span(pbegin + OFFSET, (pbegin + Extent));