FTL: Prevent InitializerList overflow
Users so far use the deduction guide, but this should not compile:
ftl::StaticVector<int, 1> vector = ftl::init::list<int>(0)(1);
Bug: 185536303
Test: m ftl_test
Change-Id: Icc1263ebdb9326948f0fc2f9c9f01f21b0b8302d
diff --git a/include/ftl/static_vector.h b/include/ftl/static_vector.h
index b7f8c29..70f1721 100644
--- a/include/ftl/static_vector.h
+++ b/include/ftl/static_vector.h
@@ -178,7 +178,9 @@
template <typename U, std::size_t Size, std::size_t... Sizes, typename... Types>
StaticVector(InitializerList<U, std::index_sequence<Size, Sizes...>, Types...>&& list)
: StaticVector(std::index_sequence<0, 0, Size>{}, std::make_index_sequence<Size>{},
- std::index_sequence<Sizes...>{}, list.tuple) {}
+ std::index_sequence<Sizes...>{}, list.tuple) {
+ static_assert(sizeof...(Sizes) < N, "Too many elements");
+ }
~StaticVector() { std::destroy(begin(), end()); }