gnucash stable: Apply -Wall -Werr -Wmissing-prototypes to C++ compilation on Windows.

John Ralls jralls at code.gnucash.org
Sun Mar 29 17:09:52 EDT 2026


Updated	 via  https://github.com/Gnucash/gnucash/commit/d42e2c5e (commit)
	from  https://github.com/Gnucash/gnucash/commit/4c159fa5 (commit)



commit d42e2c5e40216f4a587e1efaef618229174087d2
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Mar 29 13:46:27 2026 -0700

    Apply -Wall -Werr -Wmissing-prototypes to C++ compilation on Windows.
    
    And fix the resulting errors.

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 981e6c06c6..3262ed6cc1 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -644,7 +644,7 @@ if (UNIX)
 endif()
 if (MINGW)
   set( CMAKE_C_FLAGS "-Werror -Wall -Wmissing-prototypes -Wmissing-declarations ${CMAKE_C_FLAGS}")
-  set( CMAKE_CXX_FLAGS "-DWINVER=0x0500 -D_EMULATE_GLIBC=0 ${CMAKE_CXX_FLAGS}") # Workaround for bug in gtest on mingw, see https://github.com/google/googletest/issues/893 and https://github.com/google/googletest/issues/920
+  set( CMAKE_CXX_FLAGS "-Werror -Wall -Wmissing-declarations -DWINVER=0x0A00 ${CMAKE_CXX_FLAGS}") # Workaround for bug in gtest on mingw, see https://github.com/google/googletest/issues/893 and https://github.com/google/googletest/issues/920
 endif()
 
 if (APPLE)
diff --git a/gnucash/gnome/assistant-loan.cpp b/gnucash/gnome/assistant-loan.cpp
index 81fa712c2c..3316a16309 100644
--- a/gnucash/gnome/assistant-loan.cpp
+++ b/gnucash/gnome/assistant-loan.cpp
@@ -2380,7 +2380,10 @@ std::string to_str_with_prec (const gdouble val)
 				  &numfmt, nullptr, 0);
     wchar_t* buf = static_cast<wchar_t*>(malloc(sizeof(wchar_t) * size));
     GetNumberFormatW(lcid, 0, valstr.str().c_str(), &numfmt, buf, size);
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
+#pragma GCC diagnostic pop
     std::string result = conv.to_bytes(buf);
     free(buf);
     return result;
diff --git a/libgnucash/core-utils/gnc-filepath-utils.cpp b/libgnucash/core-utils/gnc-filepath-utils.cpp
index 7c62bf8c96..4f4080b2db 100644
--- a/libgnucash/core-utils/gnc-filepath-utils.cpp
+++ b/libgnucash/core-utils/gnc-filepath-utils.cpp
@@ -487,12 +487,11 @@ get_user_data_dir ()
     wchar_t path[MAX_PATH+1];
     HRESULT hr;
     LPITEMIDLIST pidl = NULL;
-    BOOL b;
 
     hr = SHGetSpecialFolderLocation (NULL, CSIDL_APPDATA, &pidl);
     if (hr == S_OK)
     {
-        b = SHGetPathFromIDListW (pidl, path);
+        [[maybe_unused]] auto b = SHGetPathFromIDListW (pidl, path);
         CoTaskMemFree (pidl);
     }
     bfs::path retval(path, cvt);
diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index f816cec0d4..9c579071b1 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -539,9 +539,9 @@ win_date_format(std::string format, struct tm tm)
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
     wchar_t buf[DATEBUFLEN];
-    memset(buf, 0, DATEBUFLEN);
+    memset(buf, 0, DATEBUFLEN * sizeof(wchar_t));
     std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> conv;
-    auto numchars = wcsftime(buf, DATEBUFLEN - 1, conv.from_bytes(format).c_str(), &tm);
+    [[maybe_unused]] auto numchars = wcsftime(buf, DATEBUFLEN - 1, conv.from_bytes(format).c_str(), &tm);
     return conv.to_bytes(buf);
 #pragma GCC diagnostic pop
 }
diff --git a/libgnucash/engine/gnc-timezone.cpp b/libgnucash/engine/gnc-timezone.cpp
index 2040aa52b1..176142e115 100644
--- a/libgnucash/engine/gnc-timezone.cpp
+++ b/libgnucash/engine/gnc-timezone.cpp
@@ -222,12 +222,12 @@ TimeZoneProvider::load_windows_dynamic_tz (HKEY key, time_zone_names names)
 	}
 	m_zone_vector.push_back (std::make_pair(max_year, tz));
    }
-    catch (std::invalid_argument)
+    catch (const std::invalid_argument& err)
     {
 	RegCloseKey (key);
 	throw;
     }
-    catch (std::bad_alloc)
+    catch (const std::bad_alloc& err)
     {
 	RegCloseKey (key);
 	throw;
@@ -249,7 +249,7 @@ TimeZoneProvider::load_windows_classic_tz (HKEY key, time_zone_names names)
 		std::make_pair(max_year, zone_from_regtzi (regtzi, names)));
 	}
     }
-    catch (std::bad_alloc)
+    catch (const std::bad_alloc& err)
     {
 	RegCloseKey (key);
 	throw;
diff --git a/libgnucash/engine/test/gtest-gnc-datetime.cpp b/libgnucash/engine/test/gtest-gnc-datetime.cpp
index 7c4a2b7e7c..6396ffdbbd 100644
--- a/libgnucash/engine/test/gtest-gnc-datetime.cpp
+++ b/libgnucash/engine/test/gtest-gnc-datetime.cpp
@@ -59,7 +59,7 @@ TEST(gnc_date_constructors, test_move_constructor)
     GncDate a(2045, 11, 13);
     GncDate b(std::move(a));
     EXPECT_TRUE(a.isnull());
-    EXPECT_TRUE (b.format("%Y-%m-%d") == "2045-11-13");
+    EXPECT_EQ (b.format("%Y-%m-%d"), "2045-11-13");
 }
 
 typedef struct
@@ -289,7 +289,7 @@ TEST(gnc_date_operators, test_move_assignment)
     GncDate b;
     b = std::move(a);
     EXPECT_TRUE(a.isnull());
-    EXPECT_TRUE (b.format("%Y-%m-%d") == "2045-11-13");
+    EXPECT_EQ (b.format("%Y-%m-%d"), "2045-11-13");
 }
 
 TEST(gnc_datetime_constructors, test_default_constructor)



Summary of changes:
 CMakeLists.txt                                | 2 +-
 gnucash/gnome/assistant-loan.cpp              | 3 +++
 libgnucash/core-utils/gnc-filepath-utils.cpp  | 3 +--
 libgnucash/engine/gnc-datetime.cpp            | 4 ++--
 libgnucash/engine/gnc-timezone.cpp            | 6 +++---
 libgnucash/engine/test/gtest-gnc-datetime.cpp | 4 ++--
 6 files changed, 12 insertions(+), 10 deletions(-)



More information about the gnucash-changes mailing list