diff --git a/include/webcpp/hash/backends/bearssl.hpp b/include/webcpp/hash/backends/bearssl.hpp index 65bd945..961de3e 100644 --- a/include/webcpp/hash/backends/bearssl.hpp +++ b/include/webcpp/hash/backends/bearssl.hpp @@ -75,9 +75,9 @@ WEBCPP_HASH_DETAIL_BEARSSL_CONFIGURATION)) #endif -// A declaration: src/canary_bearssl.c defines it, constant, in /third_party//bearssl. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BEARSSL_CANARY; +// A declaration: src/canary_bearssl.c defines it, constant, in /third_party//bearssl, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BEARSSL_CANARY; namespace webcpp::hash::backends { diff --git a/include/webcpp/hash/backends/botan.hpp b/include/webcpp/hash/backends/botan.hpp index 5b0cdd6..c690ef3 100644 --- a/include/webcpp/hash/backends/botan.hpp +++ b/include/webcpp/hash/backends/botan.hpp @@ -110,9 +110,9 @@ WEBCPP_HASH_DETAIL_MISMATCH_VALUE(botan, WEBCPP_HASH_BOTAN_COMMIT, configured)) #endif -// A declaration: src/canary_botan.cpp defines it, constant, in /third_party//botan. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BOTAN_CANARY; +// A declaration: src/canary_botan.cpp defines it, constant, in /third_party//botan, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BOTAN_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/backends/sodium.hpp b/include/webcpp/hash/backends/sodium.hpp index e12dec9..f5f4e3d 100644 --- a/include/webcpp/hash/backends/sodium.hpp +++ b/include/webcpp/hash/backends/sodium.hpp @@ -109,9 +109,9 @@ WEBCPP_HASH_DETAIL_SODIUM_CONFIGURATION)) #endif -// A declaration: src/canary_sodium.c defines it, constant, in /third_party//sodium. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_SODIUM_CANARY; +// A declaration: src/canary_sodium.c defines it, constant, in /third_party//sodium, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_SODIUM_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/blake3.hpp b/include/webcpp/hash/blake3.hpp index e206945..79e4116 100644 --- a/include/webcpp/hash/blake3.hpp +++ b/include/webcpp/hash/blake3.hpp @@ -63,9 +63,9 @@ WEBCPP_HASH_DETAIL_BLAKE3_CONFIGURATION)) #endif -// A declaration: src/canary_blake3.c defines it, constant, in /third_party//blake3. -// NOLINTNEXTLINE(bugprone-dynamic-static-initializers) -extern "C" const char WEBCPP_HASH_DETAIL_BLAKE3_CANARY; +// A declaration: src/canary_blake3.c defines it, constant, in /third_party//blake3, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_BLAKE3_CANARY; namespace webcpp::hash { diff --git a/include/webcpp/hash/digest.hpp b/include/webcpp/hash/digest.hpp index 758c9b2..9b75f7a 100644 --- a/include/webcpp/hash/digest.hpp +++ b/include/webcpp/hash/digest.hpp @@ -734,6 +734,17 @@ template > return hashed; } +// MSVC's warning C4324 ("structure was padded due to alignment specifier") is off for the hasher +// alone. A backend's state may carry an alignment specifier (libsodium's are CRYPTO_ALIGN(16) or +// CRYPTO_ALIGN(64)), so the hasher is padded after its last member to a multiple of that +// alignment, as the state requires, and no order of the members avoids it: the padding is the +// intended layout. MSVC for ARM64 reports that trailing padding under /W4, which /WX makes an +// error; MSVC for x64 reports only padding before an aligned member, never after the last one, +// and so is silent here (14.3 and 14.5 alike, msvc-lane's probe of 2026-11-23). +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4324) +#endif /** A hash fed in pieces, with one result: `make`, `update` as often as the data comes, then `finish` once (spec 2.15). @@ -924,6 +935,9 @@ class hasher { bool keyed_ = false; // made with a key: update and finish hold the timing guard phase phase_ = phase::spent; }; +#ifdef _MSC_VER +#pragma warning(pop) +#endif } // namespace webcpp::hash diff --git a/include/webcpp/hash/keccak.hpp b/include/webcpp/hash/keccak.hpp index 4d6ad5d..7757646 100644 --- a/include/webcpp/hash/keccak.hpp +++ b/include/webcpp/hash/keccak.hpp @@ -48,7 +48,9 @@ WEBCPP_HASH_DETAIL_XKCP_CONFIGURATION)) #endif -extern "C" const char WEBCPP_HASH_DETAIL_XKCP_CANARY; +// A declaration: src/canary_xkcp.c defines it, constant, in /third_party//xkcp, so its +// initialisation is static, never dynamic; constinit, on this declaration, states it. +extern "C" constinit const char WEBCPP_HASH_DETAIL_XKCP_CANARY; namespace webcpp::hash::detail { diff --git a/src/canary_botan.cpp b/src/canary_botan.cpp index 8f53bb3..f62a1a9 100644 --- a/src/canary_botan.cpp +++ b/src/canary_botan.cpp @@ -38,8 +38,9 @@ WEBCPP_HASH_DETAIL_MISMATCH_VALUE(botan, WEBCPP_HASH_BOTAN_COMMIT, WEBCPP_HASH_BOTAN_BUILT)) #endif -// The canary, constant, with C's linkage, as backends/botan.hpp declares it. -extern "C" const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, - WEBCPP_HASH_BOTAN_BUILT); -extern "C" const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, - WEBCPP_HASH_BOTAN_BUILT) = 0; +// The canary, constant, with C's linkage, as backends/botan.hpp declares it: constinit there, so +// constinit here too, on the initialising declaration, as the standard asks. +extern "C" constinit const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, + WEBCPP_HASH_BOTAN_BUILT); +extern "C" constinit const char WEBCPP_HASH_DETAIL_CANARY(botan, WEBCPP_HASH_BOTAN_COMMIT, + WEBCPP_HASH_BOTAN_BUILT) = 0;