Skip to content

Commit

Permalink
fix: work around msvc compiler bug with range-based-for in constexpr
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
muggenhor committed Sep 5, 2023
1 parent 5036dfc commit a7d4008
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/frozen/bits/pic_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "frozen/string.h"

#include <cstdint>
#include <iterator>
#include <memory>
#include <type_traits>
#include <utility>
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit a7d4008

Please sign in to comment.