https://gcc.gnu.org/g:2c19a667c2ae1e69453efe5737c5fb4c834a1f31

commit r17-5420-g2c19a667c2ae1e69453efe5737c5fb4c834a1f31
Author: Zhongteng Gui <[email protected]>
Date:   Fri Oct 16 22:07:22 2026 +0800

    c++tools: #include <stdlib.h> for malloc & free
    
    On platforms where malloc & free aren't implicitly brought in through
    other headers (e.g. building with Clang for x86_64-w64-mingw32), this
    triggers the following errors:
    
            ../../gcc-16.2.0/c++tools/resolver.cc:124:12: error: use of 
undeclared identifier 'malloc'
            124 |   buffer = xmalloc (stat.st_size);
            |            ^~~~~~~~~~~~~~~~~~~~~~
            ../../gcc-16.2.0/c++tools/resolver.cc:55:20: note: expanded from 
macro 'xmalloc'
            55 | #define xmalloc(X) malloc(X)
            |                    ^~~~~~
            ../../gcc-16.2.0/c++tools/resolver.cc:127:53: error: use of 
undeclared identifier 'free'
            127 |   struct Deleter { void operator()(void* p) const { free(p); 
} };
            |                                                     ^~~~
            2 errors generated.
    
    Fix this by directly #include <stdlib.h>.  Also change <cstring> to
    <string.h> since strlen is used without std::.
    
    c++tools/ChangeLog:
    
            * resolver.cc: Directly #include <stdlib.h> for malloc & free.
    
    Signed-off-by: Zhongteng Gui <[email protected]>
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 c++tools/resolver.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/c++tools/resolver.cc b/c++tools/resolver.cc
index 53c48b4fc6a8..e17521b91213 100644
--- a/c++tools/resolver.cc
+++ b/c++tools/resolver.cc
@@ -25,7 +25,8 @@ along with GCC; see the file COPYING3.  If not see
 #include <algorithm>
 #include <memory>
 // C
-#include <cstring>
+#include <stdlib.h> // for malloc & free
+#include <string.h> // for strlen
 // OS
 #include <fcntl.h>
 #include <unistd.h>

Reply via email to