From f0eae9292baa9932e6c5eb8d95b7552c291cfeb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antons=20Je=C4=BCkins?= Date: Tue, 16 Nov 2021 18:34:48 +0100 Subject: cmTimestamp: Declare component buffer before MinGW-specific code --- Source/cmTimestamp.cxx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx index cfea4cf..9125d7e 100644 --- a/Source/cmTimestamp.cxx +++ b/Source/cmTimestamp.cxx @@ -192,6 +192,8 @@ std::string cmTimestamp::AddTimestampComponent(char flag, } } + char buffer[16]; + #ifdef __MINGW32__ /* See a bug in MinGW: https://sourceforge.net/p/mingw-w64/bugs/793/. A work * around is to try to use strftime() from ucrtbase.dll. */ @@ -210,8 +212,6 @@ std::string cmTimestamp::AddTimestampComponent(char flag, static T strftime = loadStrftime(); #endif - char buffer[16]; - size_t size = strftime(buffer, sizeof(buffer), formatString.c_str(), &timeStruct); -- cgit v0.12 From 26c9fbab4618d53f49f92ff3a000951a1d9b9fde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antons=20Je=C4=BCkins?= Date: Tue, 16 Nov 2021 18:34:48 +0100 Subject: MINGW-w64: Fix string(TIMESTAMP) build on 32bits. Rephrase the string(TIMESTAMP) implementation not to cause gcc-11 ICE on MSYS2/mingw32. Fixes: #22916 --- Source/cmTimestamp.cxx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Source/cmTimestamp.cxx b/Source/cmTimestamp.cxx index 9125d7e..c8f5a4b 100644 --- a/Source/cmTimestamp.cxx +++ b/Source/cmTimestamp.cxx @@ -198,7 +198,7 @@ std::string cmTimestamp::AddTimestampComponent(char flag, /* See a bug in MinGW: https://sourceforge.net/p/mingw-w64/bugs/793/. A work * around is to try to use strftime() from ucrtbase.dll. */ using T = size_t(WINAPI*)(char*, size_t, const char*, const struct tm*); - auto loadStrftime = [] { + auto loadUcrtStrftime = []() -> T { auto handle = LoadLibraryExA("ucrtbase.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); if (handle) { @@ -207,9 +207,15 @@ std::string cmTimestamp::AddTimestampComponent(char flag, return reinterpret_cast(GetProcAddress(handle, "strftime")); # pragma GCC diagnostic pop } - return strftime; + return nullptr; }; - static T strftime = loadStrftime(); + static T ucrtStrftime = loadUcrtStrftime(); + + if (ucrtStrftime) { + size_t size = + ucrtStrftime(buffer, sizeof(buffer), formatString.c_str(), &timeStruct); + return std::string(buffer, size); + } #endif size_t size = -- cgit v0.12