[PATCH] libstdc++: Fix mingw-w64 build due to __max macro
Jonathan Wakely
jwakely@redhat.com
Wed Mar 11 21:32:42 GMT 2026
The stdlib.h header on mingw defines a function-like macro called __max,
which causes an error here:
include/format:3785:55: error: macro '__max' requires 2 arguments, but only 1 given
3785 | iter_difference_t<_OutIter> __max(_M_max);
We have lots of existing variables called __max, but this is the only
case that uses value-initialization and so interferes with the
function-like macro in stdlib.h
The fix proposed here is to just use copy-initialization instead.
libstdc++-v3/ChangeLog:
* include/std/format (__format::_Ptr_sink::_M_finish): Do not
use value-initialization for variable call '__max'.
* testsuite/17_intro/names.cc (__max): Define function-like
macro.
---
I've confirmed that this builds on mingw32-w64 and I'm testing it now.
libstdc++-v3/include/std/format | 2 +-
libstdc++-v3/testsuite/17_intro/names.cc | 4 ++++
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 4297bcc1007a..2a10a9200029 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3782,7 +3782,7 @@ namespace __format
if (__s.data() == _M_buf)
{
// Switched to internal buffer, so must have written _M_max.
- iter_difference_t<_OutIter> __max(_M_max);
+ iter_difference_t<_OutIter> __max = _M_max;
iter_difference_t<_OutIter> __count(_M_count + __s.size());
return { __first + __max, __count };
}
diff --git a/libstdc++-v3/testsuite/17_intro/names.cc b/libstdc++-v3/testsuite/17_intro/names.cc
index 404cc93e9630..5950e7622c89 100644
--- a/libstdc++-v3/testsuite/17_intro/names.cc
+++ b/libstdc++-v3/testsuite/17_intro/names.cc
@@ -153,6 +153,10 @@
# define __unused cannot be used as an identifier
# define __used cannot be used as an identifier
+// These are function-like macros in mingw stdlib.h
+#define __min(A,B) cannot use __min with parentheses
+#define __max(A,B) cannot use __max with parentheses
+
#ifndef __APPLE__
#define __weak predefined qualifier on darwin
#define __strong predefined qualifier on darwin
--
2.53.0
More information about the Libstdc++
mailing list