Skip to content

Commit 5e7d66f

Browse files
committed
fix(platform): Windows build — use #ifdef not if constexpr in resolver stubs; bump 0.2.6
A non-template 'if constexpr' still compiles its discarded branch, so the Windows path referenced the POSIX-only DNS helpers (under #ifndef _WIN32) and broke the Windows build (0.2.5 regression). Concentrate the preprocessor divergence in the platform module's function bodies; call sites still branch on platform::is_windows with if constexpr.
1 parent c5190fd commit 5e7d66f

2 files changed

Lines changed: 22 additions & 16 deletions

File tree

mcpp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "tinyhttps"
4-
version = "0.2.5"
4+
version = "0.2.6"
55
description = "Minimal C++23 HTTP/HTTPS client with SSE streaming support"
66
license = "Apache-2.0"
77
repo = "https://github.com/mcpplibs/tinyhttps"

src/platform.cppm

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,19 @@ inline std::vector<std::string> dns_query_a(const std::string& server, const cha
160160
// True when libc's own resolver has a usable config (/etc/resolv.conf). When
161161
// false, callers should prefer resolve_fallback() to avoid a multi-second stall
162162
// on a dead 127.0.0.1:53. Always true on Windows (the OS resolver is reliable).
163+
//
164+
// Note: the bodies branch with #ifdef, not `if constexpr` — a non-template
165+
// `if constexpr` still compiles its discarded branch, which would reference the
166+
// POSIX-only helpers above that don't exist on Windows. Concentrating that
167+
// preprocessor divergence here is exactly why this platform module exists; call
168+
// sites elsewhere branch on `is_windows` with `if constexpr`.
163169
export bool system_resolver_configured() {
164-
if constexpr (is_windows) {
165-
return true;
166-
} else {
167-
std::error_code ec;
168-
return std::filesystem::exists("/etc/resolv.conf", ec);
169-
}
170+
#ifdef _WIN32
171+
return true;
172+
#else
173+
std::error_code ec;
174+
return std::filesystem::exists("/etc/resolv.conf", ec);
175+
#endif
170176
}
171177

172178
// Resolve a hostname to IPv4 literals WITHOUT relying on libc's resolver, by
@@ -175,16 +181,16 @@ export bool system_resolver_configured() {
175181
// on query failure. A numeric host is returned unchanged.
176182
export std::vector<std::string> resolve_fallback([[maybe_unused]] const char* host,
177183
[[maybe_unused]] int timeoutMs) {
178-
if constexpr (is_windows) {
179-
return {};
180-
} else {
181-
if (is_numeric_host(host)) return { std::string(host) };
182-
for (const auto& ns : resolv_nameservers()) {
183-
auto got = dns_query_a(ns, host, timeoutMs);
184-
if (!got.empty()) return got;
185-
}
186-
return {};
184+
#ifdef _WIN32
185+
return {};
186+
#else
187+
if (is_numeric_host(host)) return { std::string(host) };
188+
for (const auto& ns : resolv_nameservers()) {
189+
auto got = dns_query_a(ns, host, timeoutMs);
190+
if (!got.empty()) return got;
187191
}
192+
return {};
193+
#endif
188194
}
189195

190196
} // namespace mcpplibs::tinyhttps::platform

0 commit comments

Comments
 (0)