public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Eli Zaretskii <eliz@gnu.org>, gcc-patches@gcc.gnu.org
Cc: gdb-patches@sourceware.org, Thomas Schwinge <thomas@codesourcery.com>
Subject: Re: MinGW compilation warnings in libiberty's xstrndup.c
Date: Fri, 19 May 2017 15:27:00 -0000	[thread overview]
Message-ID: <60a354b0-6c1a-15ea-177a-8bdb198c8c03@redhat.com> (raw)
In-Reply-To: <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

  reply	other threads:[~2017-05-19 15:22 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-08 15:37 Eli Zaretskii
2017-05-19 15:27 ` Pedro Alves [this message]
2017-05-19 15:47   ` Eli Zaretskii
2017-05-19 16:08     ` Pedro Alves
2017-05-19 22:28 ` DJ Delorie
2017-05-19 22:31   ` Pedro Alves
2017-05-19 22:56     ` DJ Delorie
2017-05-19 23:22       ` Pedro Alves
2017-05-20  1:25         ` DJ Delorie
2017-05-22 16:28           ` Pedro Alves
2017-05-26 21:49 ` DJ Delorie
2017-05-28 18:31   ` Eli Zaretskii
2017-05-31  6:17     ` DJ Delorie
2017-05-31  6:55       ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=60a354b0-6c1a-15ea-177a-8bdb198c8c03@redhat.com \
    --to=palves@redhat.com \
    --cc=eliz@gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=gdb-patches@sourceware.org \
    --cc=thomas@codesourcery.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).