Skip to content

Commit cb357a8

Browse files
committed
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.
1 parent 9e0c994 commit cb357a8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/frozen/bits/pic_array.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "frozen/string.h"
3131

3232
#include <cstdint>
33+
#include <iterator>
3334
#include <memory>
3435
#include <type_traits>
3536
#include <utility>
@@ -475,8 +476,11 @@ struct pic_array {
475476
constexpr_assert(str_value.data_size == item.size(), "size field causes truncation");
476477

477478
// constexpr std::copy before C++20
478-
for (const auto& val : item) {
479-
array_data[store_pos++] = val;
479+
// manual expansion of range-based-for because MSVC fails on that but not this
480+
using std::begin;
481+
using std::end;
482+
for (auto i = begin(item), last = end(item); i != last; ++i) {
483+
array_data[store_pos++] = *i;
480484
}
481485
if (is_nul_terminated)
482486
str_value.data_size -= 1;

0 commit comments

Comments
 (0)