From 1a62482b075a586d3a23e08b921401b00fbf715d Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Thu, 13 Feb 2025 12:02:16 +0100
Subject: [PATCH] getaddrinfo: Fix a compilation error in C++ mode (regression
 yesterday).

Reported by KO Myung-Hun <komh78@gmail.com>.

* m4/getaddrinfo.m4 (gl_GETADDRINFO): Don't set REPLACE_GETADDRINFO to 1
if getaddrinfo does not exist.
---
 ChangeLog         |  7 ++++++
 m4/getaddrinfo.m4 | 56 ++++++++++++++++++++++++-----------------------
 2 files changed, 36 insertions(+), 27 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8f5b7302b0..51a17c3354 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-02-13  Bruno Haible  <bruno@clisp.org>
+
+	getaddrinfo: Fix a compilation error in C++ mode (regression yesterday).
+	Reported by KO Myung-Hun <komh78@gmail.com>.
+	* m4/getaddrinfo.m4 (gl_GETADDRINFO): Don't set REPLACE_GETADDRINFO to 1
+	if getaddrinfo does not exist.
+
 2025-02-12  Bruno Haible  <bruno@clisp.org>
 
 	setlocale: Update info about Galician and Tamil.
diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4
index 19ae42cc15..5207f0565f 100644
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
 # getaddrinfo.m4
-# serial 36
+# serial 37
 dnl Copyright (C) 2004-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -89,10 +89,11 @@ int getaddrinfo (const char *, const char *, const struct addrinfo *, struct add
       HAVE_GETADDRINFO=0
     fi
   fi
-  AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICSERV],
-    [gl_cv_func_getaddrinfo_works],
-    [AC_RUN_IFELSE(
-       [AC_LANG_PROGRAM([[
+  if test $HAVE_GETADDRINFO != 0; then
+    AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICSERV],
+      [gl_cv_func_getaddrinfo_works],
+      [AC_RUN_IFELSE(
+         [AC_LANG_PROGRAM([[
 #include <sys/types.h>
 #ifdef HAVE_SYS_SOCKET_H
 #include <sys/socket.h>
@@ -105,28 +106,29 @@ int getaddrinfo (const char *, const char *, const struct addrinfo *, struct add
 #endif
 #include <stddef.h>
 #include <string.h>
-          ]], [[
-          struct addrinfo hints;
-          struct addrinfo ai;
-          memset (&hints, 0, sizeof (hints));
-          hints.ai_flags = AI_NUMERICSERV;
-          return getaddrinfo ("www.gnu.org", "http", &hints, &ai) != EAI_NONAME;
-          ]])
-       ],
-       [gl_cv_func_getaddrinfo_works=yes],
-       [gl_cv_func_getaddrinfo_works=no],
-       [case "$host_os" in
-                             # Guess no on native Windows.
-          mingw* | windows*) gl_cv_func_getaddrinfo_works="guessing no" ;;
-                             # Guess yes otherwise.
-          *)                 gl_cv_func_getaddrinfo_works="guessing yes" ;;
-        esac
-       ])
-    ])
-  case "$gl_cv_func_getaddrinfo_works" in
-    *yes) ;;
-    *) REPLACE_GETADDRINFO=1 ;;
-  esac
+            ]], [[
+              struct addrinfo hints;
+              struct addrinfo ai;
+              memset (&hints, 0, sizeof (hints));
+              hints.ai_flags = AI_NUMERICSERV;
+              return getaddrinfo ("www.gnu.org", "http", &hints, &ai) != EAI_NONAME;
+            ]])
+         ],
+         [gl_cv_func_getaddrinfo_works=yes],
+         [gl_cv_func_getaddrinfo_works=no],
+         [case "$host_os" in
+                               # Guess no on native Windows.
+            mingw* | windows*) gl_cv_func_getaddrinfo_works="guessing no" ;;
+                               # Guess yes otherwise.
+            *)                 gl_cv_func_getaddrinfo_works="guessing yes" ;;
+          esac
+         ])
+      ])
+    case "$gl_cv_func_getaddrinfo_works" in
+      *yes) ;;
+      *) REPLACE_GETADDRINFO=1 ;;
+    esac
+  fi
   AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO],
     [Define to 1 if getaddrinfo exists, or to 0 otherwise.])
 
-- 
2.39.5