Hi John, Thanks for this report.
> The current gnulib unistd.in.h file includes the following section: > > #if @GNULIB_GETHOSTNAME@ > /* Get all possible declarations of gethostname(). */ > # if @UNISTD_H_HAVE_WINSOCK2_H@ > # if !defined _GL_SYS_SOCKET_H > # undef socket > # define socket socket_used_without_including_sys_socket_h > # undef connect > # define connect connect_used_without_including_sys_socket_h > # undef accept > # define accept accept_used_without_including_sys_socket_h > # undef bind > # define bind bind_used_without_including_sys_socket_h > # undef getpeername > # define getpeername > getpeername_used_without_including_sys_socket_h > # undef getsockname > # define getsockname > getsockname_used_without_including_sys_socket_h > # undef getsockopt > # define getsockopt > getsockopt_used_without_including_sys_socket_h > # undef listen > # define listen listen_used_without_including_sys_socket_h > # undef recv > # define recv recv_used_without_including_sys_socket_h > # undef send > # define send send_used_without_including_sys_socket_h > # undef recvfrom > # define recvfrom recvfrom_used_without_including_sys_socket_h > # undef sendto > # define sendto sendto_used_without_including_sys_socket_h > # undef setsockopt > # define setsockopt > setsockopt_used_without_including_sys_socket_h > # undef shutdown > # define shutdown shutdown_used_without_including_sys_socket_h > # endif > # if !defined _GL_SYS_SELECT_H > # undef select > # define select select_used_without_including_sys_select_h > # endif > # endif > #endif > > I think these definitions can cause trouble for C++ programs that do > things like > > foo.h: > ----- > class foo { > public: > foo (void) { } > void accept (void); > }; > > foo.cc: > ------ > #include <unistd.h> > #include "foo.h" > void foo::accept (void) { } > // Oops, accept is not a member of class foo. Indeed. I'm applying the attached patch; it should fix this. > or C programs like this: > > foo.h: > ----- > extern int accept; > extern void doit (void); > > foo.c: > ----- > #include <unistd.h> > #include "foo.h" > int accept = 0; > void doit (void) { accept = 1; } > > main.c: > ------ > #include "foo.h" > int main (void) { accept = -1; doit (); return accept; } > /* oops, what happened to the global variable accept? */ C programs in a POSIX environment must not define global variables named 'accept'. 2010-03-28 Bruno Haible <br...@clisp.org> unistd: Avoid #define replacements in C++ mode. * lib/unistd.in.h (socket, connect, accept, bind, getpeername, getsockname, getsockopt, listen, recv, send, recvfrom, sendto, setsockopt, shutdown, select): In C++, attach a warning to the function if possible, rather than #defining the symbol to a dysfunctional alias. Reported by John W. Eaton <j...@gnu.org>. *** lib/unistd.in.h.orig Sun Mar 28 14:22:45 2010 --- lib/unistd.in.h Sun Mar 28 13:54:06 2010 *************** *** 97,148 **** # include <getopt.h> #endif #if @GNULIB_GETHOSTNAME@ /* Get all possible declarations of gethostname(). */ # if @UNISTD_H_HAVE_WINSOCK2_H@ # if !defined _GL_SYS_SOCKET_H ! # undef socket ! # define socket socket_used_without_including_sys_socket_h ! # undef connect ! # define connect connect_used_without_including_sys_socket_h ! # undef accept ! # define accept accept_used_without_including_sys_socket_h ! # undef bind ! # define bind bind_used_without_including_sys_socket_h ! # undef getpeername ! # define getpeername getpeername_used_without_including_sys_socket_h ! # undef getsockname ! # define getsockname getsockname_used_without_including_sys_socket_h ! # undef getsockopt ! # define getsockopt getsockopt_used_without_including_sys_socket_h ! # undef listen ! # define listen listen_used_without_including_sys_socket_h ! # undef recv ! # define recv recv_used_without_including_sys_socket_h ! # undef send ! # define send send_used_without_including_sys_socket_h ! # undef recvfrom ! # define recvfrom recvfrom_used_without_including_sys_socket_h ! # undef sendto ! # define sendto sendto_used_without_including_sys_socket_h ! # undef setsockopt ! # define setsockopt setsockopt_used_without_including_sys_socket_h ! # undef shutdown ! # define shutdown shutdown_used_without_including_sys_socket_h # endif # if !defined _GL_SYS_SELECT_H ! # undef select ! # define select select_used_without_including_sys_select_h # endif # endif #endif - /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ - - /* The definition of _GL_ARG_NONNULL is copied here. */ - - /* The definition of _GL_WARN_ON_USE is copied here. */ - /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO --- 97,185 ---- # include <getopt.h> #endif + /* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */ + + /* The definition of _GL_ARG_NONNULL is copied here. */ + + /* The definition of _GL_WARN_ON_USE is copied here. */ + + #if @GNULIB_GETHOSTNAME@ /* Get all possible declarations of gethostname(). */ # if @UNISTD_H_HAVE_WINSOCK2_H@ # if !defined _GL_SYS_SOCKET_H ! # if !(defined __cplusplus && defined GNULIB_NAMESPACE) ! # undef socket ! # define socket socket_used_without_including_sys_socket_h ! # undef connect ! # define connect connect_used_without_including_sys_socket_h ! # undef accept ! # define accept accept_used_without_including_sys_socket_h ! # undef bind ! # define bind bind_used_without_including_sys_socket_h ! # undef getpeername ! # define getpeername getpeername_used_without_including_sys_socket_h ! # undef getsockname ! # define getsockname getsockname_used_without_including_sys_socket_h ! # undef getsockopt ! # define getsockopt getsockopt_used_without_including_sys_socket_h ! # undef listen ! # define listen listen_used_without_including_sys_socket_h ! # undef recv ! # define recv recv_used_without_including_sys_socket_h ! # undef send ! # define send send_used_without_including_sys_socket_h ! # undef recvfrom ! # define recvfrom recvfrom_used_without_including_sys_socket_h ! # undef sendto ! # define sendto sendto_used_without_including_sys_socket_h ! # undef setsockopt ! # define setsockopt setsockopt_used_without_including_sys_socket_h ! # undef shutdown ! # define shutdown shutdown_used_without_including_sys_socket_h ! # else ! _GL_WARN_ON_USE (socket, ! "socket() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (connect, ! "connect() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (accept, ! "accept() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (bind, ! "bind() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (getpeername, ! "getpeername() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (getsockname, ! "getsockname() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (getsockopt, ! "getsockopt() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (listen, ! "listen() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (recv, ! "recv() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (send, ! "send() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (recvfrom, ! "recvfrom() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (sendto, ! "sendto() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (setsockopt, ! "setsockopt() used without including <sys/socket.h>"); ! _GL_WARN_ON_USE (shutdown, ! "shutdown() used without including <sys/socket.h>"); ! # endif # endif # if !defined _GL_SYS_SELECT_H ! # if !(defined __cplusplus && defined GNULIB_NAMESPACE) ! # undef select ! # define select select_used_without_including_sys_select_h ! # else ! _GL_WARN_ON_USE (select, ! "select() used without including <sys/select.h>"); ! # endif # endif # endif #endif /* OS/2 EMX lacks these macros. */ #ifndef STDIN_FILENO