bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

stdio: Fix compilation error in C++ mode on macOS


From: Bruno Haible
Subject: stdio: Fix compilation error in C++ mode on macOS
Date: Fri, 07 Apr 2023 23:46:12 +0200

Building a testdir of vasnwprintf-posix on macOS 12.5, I get these two
compilation errors:

In file included from ../../gltests/test-assert-h-c++.cc:26:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:37:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:214:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:15:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/string:519:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__debug:14:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:98:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__mbstate_t.h:29:
In file included from ../gllib/wchar.h:80:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/wchar.h:123:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h:90:
../gllib/stdio.h:1508:19: error: no member named 'getw' in the global namespace
_GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/stdlib.h:404:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
                 ~~^
In file included from ../../gltests/test-assert-h-c++.cc:26:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iostream:37:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/ios:214:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__locale:15:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/string:519:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__debug:14:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/iosfwd:98:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__mbstate_t.h:29:
In file included from ../gllib/wchar.h:80:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/wchar.h:123:
In file included from 
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/wchar.h:90:
../gllib/stdio.h:1751:19: error: no member named 'putw' in the global namespace
_GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../gllib/stdlib.h:404:20: note: expanded from macro '_GL_CXXALIAS_SYS'
          return ::func;                                      \
                 ~~^

This cause is that the declarations of these two functions in
/usr/include/stdio.h are dependent on the value of _POSIX_C_SOURCE.
Apparently this macro has different value in a C++ compilation unit
than in C.

This patch fixes the errors.


2023-04-07  Bruno Haible  <bruno@clisp.org>

        stdio: Fix compilation error in C++ mode on macOS.
        * lib/stdio.in.h (getw, putw): Repeat the declaration even if the
        function is already supposed to be declared.

diff --git a/lib/stdio.in.h b/lib/stdio.in.h
index 0ed3e7595c..69242b6c36 100644
--- a/lib/stdio.in.h
+++ b/lib/stdio.in.h
@@ -998,6 +998,10 @@ _GL_WARN_ON_USE (gets, "gets is a security hole - use 
fgets instead");
 _GL_CXXALIAS_MDA (getw, int, (FILE *restrict stream));
 # else
 #  if @HAVE_DECL_GETW@
+#   if defined __APPLE__ && defined __MACH__
+/* The presence of the declaration depends on _POSIX_C_SOURCE.  */
+_GL_FUNCDECL_SYS (getw, int, (FILE *restrict stream));
+#   endif
 _GL_CXXALIAS_SYS (getw, int, (FILE *restrict stream));
 #  endif
 # endif
@@ -1241,6 +1245,10 @@ _GL_CXXALIASWARN (puts);
 _GL_CXXALIAS_MDA (putw, int, (int w, FILE *restrict stream));
 # else
 #  if @HAVE_DECL_PUTW@
+#   if defined __APPLE__ && defined __MACH__
+/* The presence of the declaration depends on _POSIX_C_SOURCE.  */
+_GL_FUNCDECL_SYS (putw, int, (int w, FILE *restrict stream));
+#   endif
 _GL_CXXALIAS_SYS (putw, int, (int w, FILE *restrict stream));
 #  endif
 # endif






reply via email to

[Prev in Thread] Current Thread [Next in Thread]