diff --git a/include/nlohmann/detail/input/json_sax.hpp b/include/nlohmann/detail/input/json_sax.hpp
index d4c32913..223acd60 100644
--- a/include/nlohmann/detail/input/json_sax.hpp
+++ b/include/nlohmann/detail/input/json_sax.hpp
@@ -263,7 +263,7 @@ class json_sax_dom_parser
                      const Exception& ex)
     {
         errored = true;
-        (void)ex;
+        static_cast<void>(ex);
         if (allow_exceptions)
         {
             JSON_THROW(ex);
@@ -502,7 +502,7 @@ class json_sax_dom_callback_parser
                      const Exception& ex)
     {
         errored = true;
-        (void)ex;
+        static_cast<void>(ex);
         if (allow_exceptions)
         {
             JSON_THROW(ex);
diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp
index 67beb73a..c41df0e8 100644
--- a/single_include/nlohmann/json.hpp
+++ b/single_include/nlohmann/json.hpp
@@ -5441,7 +5441,7 @@ class json_sax_dom_parser
                      const Exception& ex)
     {
         errored = true;
-        (void)ex;
+        static_cast<void>(ex);
         if (allow_exceptions)
         {
             JSON_THROW(ex);
@@ -5680,7 +5680,7 @@ class json_sax_dom_callback_parser
                      const Exception& ex)
     {
         errored = true;
-        (void)ex;
+        static_cast<void>(ex);
         if (allow_exceptions)
         {
             JSON_THROW(ex);