diff --git a/src/pugixml.cpp b/src/pugixml.cpp
index b8847a4bf070b7806bba419b2de3aeafc0d6b053..dd3f4274e2c128a3c7e01d699c6a31944dda66b4 100644
--- a/src/pugixml.cpp
+++ b/src/pugixml.cpp
@@ -3995,7 +3995,7 @@ PUGI__NS_BEGIN
 		_fseeki64(file, 0, SEEK_END);
 		length_type length = _ftelli64(file);
 		_fseeki64(file, 0, SEEK_SET);
-	#elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && !(defined(__STRICT_ANSI__) && __GNUC__ * 100 + __GNUC_MINOR__ <= 405)
+	#elif defined(__MINGW32__) && !defined(__NO_MINGW_LFS) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR))
 		// there are 64-bit versions of fseek/ftell, let's use them
 		typedef off64_t length_type;
 
@@ -4240,7 +4240,7 @@ PUGI__NS_BEGIN
 	}
 #endif
 
-#if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && !(defined(__STRICT_ANSI__) && __GNUC__ * 100 + __GNUC_MINOR__ <= 405))
+#if defined(PUGI__MSVC_CRT_VERSION) || defined(__BORLANDC__) || (defined(__MINGW32__) && (!defined(__STRICT_ANSI__) || defined(__MINGW64_VERSION_MAJOR)))
 	PUGI__FN FILE* open_file_wide(const wchar_t* path, const wchar_t* mode)
 	{
 		return _wfopen(path, mode);
diff --git a/tests/test_document.cpp b/tests/test_document.cpp
index f57465f188836681fdce2443f7d4ea05ee4feb85..ebcdcd1f694e29ba4a435c709a90e3b9e9b887c7 100644
--- a/tests/test_document.cpp
+++ b/tests/test_document.cpp
@@ -323,7 +323,7 @@ TEST(document_load_file_wide_ascii)
 	CHECK_NODE(doc, STR("<node />"));
 }
 
-#if !defined(__DMC__) && !defined(__MWERKS__) && !(defined(__MINGW32__) && defined(__STRICT_ANSI__) && __GNUC__ * 100 + __GNUC_MINOR__ <= 405)
+#if !defined(__DMC__) && !defined(__MWERKS__) && !(defined(__MINGW32__) && defined(__STRICT_ANSI__) && !defined(__MINGW64_VERSION_MAJOR))
 TEST(document_load_file_wide_unicode)
 {
 	pugi::xml_document doc;