[gcc r16-8033] libstdc++: Fix mingw-w64 build due to __max macro

Jonathan Wakely redi@gcc.gnu.org
Thu Mar 12 09:26:56 GMT 2026


https://gcc.gnu.org/g:e397f2547a66d091b6f214c1340577d497260d0b

commit r16-8033-ge397f2547a66d091b6f214c1340577d497260d0b
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Mar 11 21:22:12 2026 +0000

    libstdc++: Fix mingw-w64 build due to __max macro
    
    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 direct-initialization and so interferes with the
    function-like macro in stdlib.h
    
    The fix applied here is just to rename the variable. We can't use
    direct-list-initialization because the conversion from size_t to the
    difference type would be narrowing. We prefer not to use
    copy-initialization so that conversion to the difference type is
    explicit not implicit.
    
    libstdc++-v3/ChangeLog:
    
            * include/std/format (__format::_Ptr_sink::_M_finish): Rename
            __max variable to __m.
            * testsuite/17_intro/names.cc (__max): Define function-like
            macro.
    
    Reviewed-by: Tomasz Kamiński <tkaminsk@redhat.com>

Diff:
---
 libstdc++-v3/include/std/format          | 4 ++--
 libstdc++-v3/testsuite/17_intro/names.cc | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/std/format b/libstdc++-v3/include/std/format
index 4297bcc1007a..555781bbd274 100644
--- a/libstdc++-v3/include/std/format
+++ b/libstdc++-v3/include/std/format
@@ -3782,9 +3782,9 @@ 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> __m(_M_max);
 	      iter_difference_t<_OutIter> __count(_M_count + __s.size());
-	      return { __first + __max, __count };
+	      return { __first + __m, __count };
 	    }
 	  else // Not using internal buffer yet
 	    {
diff --git a/libstdc++-v3/testsuite/17_intro/names.cc b/libstdc++-v3/testsuite/17_intro/names.cc
index 404cc93e9630..f56c045fedf7 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


More information about the Libstdc++-cvs mailing list