From a7d400896b25ea0b110706ac65e96f99e1305863 Mon Sep 17 00:00:00 2001 From: Giel van Schijndel Date: Tue, 29 Aug 2023 13:25:42 +0200 Subject: [PATCH] fix: work around msvc compiler bug with range-based-for in constexpr For some unknown reason MSVC fails to evaluate at constant-evalutation-time (constexpr) pic_array::appender::operator() when it uses a range-based-for expression. Manually expanding it, in the exact same way that the C++ spec says "the implementation" (compiler) should do it, allows it to proceed. --- include/frozen/bits/pic_array.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/frozen/bits/pic_array.h b/include/frozen/bits/pic_array.h index 97fb5e4b..671c8f75 100644 --- a/include/frozen/bits/pic_array.h +++ b/include/frozen/bits/pic_array.h @@ -30,6 +30,7 @@ #include "frozen/string.h" #include +#include #include #include #include @@ -475,8 +476,11 @@ struct pic_array { constexpr_assert(str_value.data_size == item.size(), "size field causes truncation"); // constexpr std::copy before C++20 - for (const auto& val : item) { - array_data[store_pos++] = val; + // manual expansion of range-based-for because MSVC fails on that but not this + using std::begin; + using std::end; + for (auto i = begin(item), last = end(item); i != last; ++i) { + array_data[store_pos++] = *i; } if (is_nul_terminated) str_value.data_size -= 1;