Skip to content

Commit d2cd44d

Browse files
authored
MSVC fixes (#2304)
* MSVC fixes * Update dragonbox.hpp * More MSVC warning fixes * More MSVC fixes * avoid MSVC unreachable code warnings * #pragma warning(push/disable/pop) * fix MSVC * more msvc fixes * msvc fixes * more warning fixes * Update value_based_skip_test.cpp * increase msvc workflow timeout * Add 2 minute timeouts for msvc tests * longer timeouts * fix temp_file_path for windows
1 parent 82704ca commit d2cd44d

File tree

27 files changed

+177
-77
lines changed

27 files changed

+177
-77
lines changed

.github/workflows/msvc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env:
2323
jobs:
2424
build:
2525
runs-on: windows-2025-vs2026
26-
timeout-minutes: 10
26+
timeout-minutes: 30
2727

2828
strategy:
2929
matrix:
@@ -40,4 +40,4 @@ jobs:
4040

4141
- name: Test
4242
working-directory: build
43-
run: ctest --build-config ${{env.BUILD_TYPE}}
43+
run: ctest --build-config ${{env.BUILD_TYPE}} --timeout 300

include/glaze/beve/read.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,10 @@ namespace glz
16191619
}
16201620
};
16211621

1622+
#if defined(_MSC_VER)
1623+
#pragma warning(push)
1624+
#pragma warning(disable : 4702) // unreachable code from if constexpr
1625+
#endif
16221626
template <class T>
16231627
requires((glaze_object_t<T> || reflectable<T>) && not custom_read<T>)
16241628
struct from<BEVE, T> final
@@ -1693,6 +1697,9 @@ namespace glz
16931697
++it;
16941698

16951699
static constexpr auto N = reflect<T>::size;
1700+
if constexpr (N == 0) {
1701+
(void)value;
1702+
}
16961703

16971704
static constexpr bit_array<N> all_fields = [] {
16981705
bit_array<N> arr{};
@@ -1825,6 +1832,9 @@ namespace glz
18251832
}
18261833
}
18271834
};
1835+
#if defined(_MSC_VER)
1836+
#pragma warning(pop)
1837+
#endif
18281838

18291839
template <class T>
18301840
requires glaze_array_t<T>

include/glaze/beve/write.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,6 +1341,11 @@ namespace glz
13411341
}
13421342

13431343
// Second pass: write members
1344+
1345+
#ifdef _MSC_VER
1346+
#pragma warning(push)
1347+
#pragma warning(disable : 4702) // unreachable code from if constexpr
1348+
#endif
13441349
for_each<N>([&]<size_t I>() {
13451350
if (bool(ctx.error)) [[unlikely]] {
13461351
return;
@@ -1403,6 +1408,9 @@ namespace glz
14031408
}
14041409
}
14051410
});
1411+
#ifdef _MSC_VER
1412+
#pragma warning(pop)
1413+
#endif
14061414
}
14071415
else {
14081416
// Static path: use compile-time count for better performance

include/glaze/cbor/read.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,10 @@ namespace glz
13061306
}
13071307
};
13081308

1309+
#if defined(_MSC_VER)
1310+
#pragma warning(push)
1311+
#pragma warning(disable : 4702) // unreachable code from if constexpr
1312+
#endif
13091313
// Glaze objects (structs with reflection)
13101314
template <class T>
13111315
requires((glaze_object_t<T> || reflectable<T>) && !custom_read<T>)
@@ -1334,6 +1338,9 @@ namespace glz
13341338
}
13351339

13361340
static constexpr auto N = reflect<T>::size;
1341+
if constexpr (N == 0) {
1342+
(void)value;
1343+
}
13371344

13381345
uint64_t n_keys;
13391346
if (additional_info == info::indefinite) {
@@ -1448,6 +1455,9 @@ namespace glz
14481455
}
14491456
}
14501457
};
1458+
#if defined(_MSC_VER)
1459+
#pragma warning(pop)
1460+
#endif
14511461

14521462
// Tuples
14531463
template <class T>

include/glaze/csv/read.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,10 @@ namespace glz
493493
using Row = typename T::value_type;
494494
using Value = typename Row::value_type;
495495

496+
#ifdef _MSC_VER
497+
#pragma warning(push)
498+
#pragma warning(disable : 4702) // unreachable code from if constexpr
499+
#endif
496500
template <auto Opts, class It>
497501
static void op(auto&& value, is_context auto&& ctx, It&& it, auto end)
498502
{
@@ -796,6 +800,9 @@ namespace glz
796800
}
797801
}
798802
}
803+
#ifdef _MSC_VER
804+
#pragma warning(pop)
805+
#endif
799806
};
800807

801808
template <char delim>

include/glaze/json/read.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,11 +3770,11 @@ namespace glz
37703770
constexpr auto variant_size = std::variant_size_v<T>;
37713771
if constexpr (ids_size < variant_size) {
37723772
// Use the first unlabeled type as the default
3773-
const auto type_index = ids_size;
3773+
const auto default_type_index = ids_size;
37743774

37753775
it = start; // we restart our object parsing now that we know the target type
3776-
tag_specified_index = type_index; // Store the default type index
3777-
if (value.index() != type_index) emplace_runtime_variant(value, type_index);
3776+
tag_specified_index = default_type_index; // Store the default type index
3777+
if (value.index() != default_type_index) emplace_runtime_variant(value, default_type_index);
37783778
std::visit(
37793779
[&](auto&& v) {
37803780
using V = std::decay_t<decltype(v)>;

include/glaze/json/write.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,10 @@ namespace glz
544544
constexpr bool write_can_error()
545545
{
546546
using V = std::remove_cvref_t<T>;
547-
if constexpr (requires {
547+
if constexpr (always_skipped<V>) {
548+
return false; // hidden/skip types are never written
549+
}
550+
else if constexpr (requires {
548551
{ to<JSON, V>::can_error } -> std::convertible_to<bool>;
549552
}) {
550553
return to<JSON, V>::can_error;

include/glaze/msgpack/write.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,10 @@ namespace glz
708708
}
709709
};
710710

711+
#ifdef _MSC_VER
712+
#pragma warning(push)
713+
#pragma warning(disable : 4702) // unreachable code from if constexpr
714+
#endif
711715
template <writable_array_t T>
712716
struct to<MSGPACK, T>
713717
{
@@ -740,6 +744,9 @@ namespace glz
740744
}
741745
}
742746
}
747+
#ifdef _MSC_VER
748+
#pragma warning(pop)
749+
#endif
743750
};
744751

745752
template <>

include/glaze/net/http_server.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,7 +2146,13 @@ namespace glz
21462146
auto time_t_now = std::chrono::system_clock::to_time_t(now);
21472147

21482148
char buf[100];
2149+
#ifdef _MSC_VER
2150+
std::tm tm_buf;
2151+
gmtime_s(&tm_buf, &time_t_now);
2152+
std::strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", &tm_buf);
2153+
#else
21492154
std::strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", std::gmtime(&time_t_now));
2155+
#endif
21502156

21512157
return buf;
21522158
}

include/glaze/net/websocket_connection.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ namespace glz
153153
size_t i = 0;
154154
size_t j = (context->count[0] >> 3) & 63;
155155

156-
if ((context->count[0] += uint32_t(len << 3)) < (len << 3)) context->count[1]++;
157-
context->count[1] += (len >> 29);
156+
if ((context->count[0] += uint32_t(len << 3)) < uint32_t(len << 3)) context->count[1]++;
157+
context->count[1] += uint32_t(len >> 29);
158158

159159
if ((j + len) > 63) {
160160
std::memcpy(&context->buffer[j], data, (i = 64 - j));

0 commit comments

Comments
 (0)