This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: MinGW compilation warnings in libiberty's xstrndup.c
- From: Pedro Alves <palves at redhat dot com>
- To: Eli Zaretskii <eliz at gnu dot org>, gcc-patches at gcc dot gnu dot org
- Cc: gdb-patches at sourceware dot org, Thomas Schwinge <thomas at codesourcery dot com>
- Date: Fri, 19 May 2017 16:22:55 +0100
- Subject: Re: MinGW compilation warnings in libiberty's xstrndup.c
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=palves at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 8111380C00
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 8111380C00
- References: <83h90vcqo6.fsf@gnu.org>
[Adding Thomas]
On 05/08/2017 04:30 PM, Eli Zaretskii wrote:
> When compiling libiberty (as part of GDB) with MinGW on MS-Windows, I
> see the following warning:
>
> gcc -c -DHAVE_CONFIG_H -O2 -gdwarf-4 -g3 -D__USE_MINGW_ACCESS -I. -I./../include -W -Wall -Wwrite-strings -Wc++-compat -Wstrict-prototypes -pedantic -D_GNU_SOURCE ./xstrndup.c -o xstrndup.o
> ./xstrndup.c: In function 'xstrndup':
> ./xstrndup.c:51:16: warning: implicit declaration of function 'strnlen' [-Wimplicit-function-declaration]
> size_t len = strnlen (s, n);
> ^
>
> This happens because libiberty.h uses incorrect guards for the
> prototype of strnlen:
>
> #if defined (HAVE_DECL_STRNLEN) && !HAVE_DECL_STRNLEN
> extern size_t strnlen (const char *, size_t);
> #endif
>
> It should use HAVE_STRNLEN instead, because that's the only
> strnlen-related macro defined in config.g when strnlen is probed by
> the configure script.
Looks like the declaration check got added to gcc's configure, but not
elsewhere, with:
commit d968efeac356364c01445013a1a3660e5087cb15
Author: tschwinge <tschwinge@138bc75d-0d04-0410-961f-82ee72b054a4>
AuthorDate: Tue Jun 10 09:45:00 2014 +0000
[PR lto/61334] Declare prototype for strnlen, if needed.
include/
* libiberty.h [defined (HAVE_DECL_STRNLEN) &&
!HAVE_DECL_STRNLEN] (strnlen): New prototype.
gcc/
* configure.ac: Use gcc_AC_CHECK_DECLS to check for strnlen
prototype.
* config.in: Regenerate.
* configure: Likewise.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@211401 138bc75d-0d04-0410-961f-82ee72b054a4
But then, xstrndup.c has at the top:
#ifdef HAVE_STRING_H
#include <string.h>
#else
# ifdef HAVE_STRINGS_H
# include <strings.h>
# endif
#endif
So I would expect your build to pick the strnlen declaration from
one of the string.h or strings.h mingw headers. Why didn't it?
Thanks,
Pedro Alves