From 27992edaf7745f2ba635a35875b525f1e86e7874 Mon Sep 17 00:00:00 2001 From: Tuomo Kriikkula Date: Sat, 29 Jun 2024 18:42:01 +0300 Subject: [PATCH] Add MSVC note, explicit constexpr lambdas --- tests/test_randomized.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/tests/test_randomized.cpp b/tests/test_randomized.cpp index eb00d4d..83b3458 100644 --- a/tests/test_randomized.cpp +++ b/tests/test_randomized.cpp @@ -105,7 +105,7 @@ constexpr std::u16string get_rand_str(std::integer_sequence sl { std::u16string str_in; str_in.reserve(slen_seq.size()); - boost::hana::for_each(slen_seq, [&str_in](const auto i) + boost::hana::for_each(slen_seq, [&str_in](const auto i) constexpr { constexpr auto i64 = static_cast(i); constexpr auto rnd = get_rand(); @@ -125,7 +125,7 @@ std::vector<::umb::byte> get_rand_bytes(std::integer_sequence { std::vector<::umb::byte> bytes; bytes.reserve(blen_seq.size()); - boost::hana::for_each(blen_seq, [&](const auto i) + boost::hana::for_each(blen_seq, [&](const auto i) constexpr { constexpr auto i64 = static_cast(i); constexpr auto rnd_idx = get_rand(); @@ -182,14 +182,17 @@ TEST_CASE("test TestMessages messages with randomized data") std::cout << std::format("*** begin RNG tests, r_initial={}, kiss_seed={} ***\n\n", r_initial, ::umb::meta::rng::kiss_seed); + // TODO: this does not work on MSVC currently. Compiler bug? + // See: https://developercommunity.visualstudio.com/t/Capture-of-constexpr-variable-not-workin/10190629?sort=active&topics=windows+10.0 + boost::hana::for_each(rounds, [ &seq = std::as_const(seq), seq_size - ](const auto round) + ](const auto round) constexpr { std::cout << std::format("\n####### round: {}\n", static_cast(round)); - boost::hana::for_each(seq, [round, seq_size](const auto index) + boost::hana::for_each(seq, [round, seq_size](const auto index) constexpr { constexpr auto idx = decltype(index)::value; constexpr auto mt = static_cast<::testmessages::umb::MessageType>(idx); @@ -210,7 +213,7 @@ TEST_CASE("test TestMessages messages with randomized data") boost::hana::for_each(field_seq, [ round, idx, seq_size, message, field_seq_size, mt - ](const auto findex) + ](const auto findex) constexpr { constexpr auto field = meta::Message::template field(); constexpr uint64_t rng_iter =