[2/3] include/dis-asm.h: Fix warning: Include "string.h" for strchr

Message ID 20181202130510.10056-3-shorne@gmail.com
State New, archived
Headers

Commit Message

Stafford Horne Dec. 2, 2018, 1:05 p.m. UTC
  I got this warning when building the OpenRISC sim target.

Warning:

In file included from ../../../binutils-gdb/sim/or1k/../common/cgen-trace.c:26:
../../../binutils-gdb/sim/or1k/../../include/dis-asm.h: In function ‘next_disassembler_option’:
../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: implicit declaration of function ‘strchr’ [-Wimplicit-function-declaration]
   const char *opt = strchr (options, ',');
                     ^~~~~~
../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: incompatible implicit declaration of built-in function ‘strchr’
../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: note: include ‘<string.h>’ or provide a declaration of ‘strchr’
../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:40:1:
+#include <string.h>

../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21:
   const char *opt = strchr (options, ',');
                     ^~~~~~

include/ChangeLog:

	dis-asm.h: Include "string.h"
---
 include/dis-asm.h | 4 ++++
 1 file changed, 4 insertions(+)
  

Comments

Simon Marchi Jan. 22, 2019, 5:07 p.m. UTC | #1
On 2018-12-02 8:05 a.m., Stafford Horne wrote:
> I got this warning when building the OpenRISC sim target.

> 

> Warning:

> 

> In file included from ../../../binutils-gdb/sim/or1k/../common/cgen-trace.c:26:

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h: In function ‘next_disassembler_option’:

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: implicit declaration of function ‘strchr’ [-Wimplicit-function-declaration]

>    const char *opt = strchr (options, ',');

>                      ^~~~~~

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: incompatible implicit declaration of built-in function ‘strchr’

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: note: include ‘<string.h>’ or provide a declaration of ‘strchr’

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:40:1:

> +#include <string.h>

> 

> ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21:

>    const char *opt = strchr (options, ',');

>                      ^~~~~~

> 

> include/ChangeLog:

> 

> 	dis-asm.h: Include "string.h"

> ---

>  include/dis-asm.h | 4 ++++

>  1 file changed, 4 insertions(+)

> 

> diff --git a/include/dis-asm.h b/include/dis-asm.h

> index 84627950c0..823bba5b45 100644

> --- a/include/dis-asm.h

> +++ b/include/dis-asm.h

> @@ -32,6 +32,10 @@ extern "C" {

>  #endif

>  

>  #include <stdio.h>

> +/* For strchr.  */

> +#ifdef HAVE_STRING_H

> +#include <string.h>

> +#endif

>  #include "bfd.h"

>  

>    typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;

> 


Hi Stafford,

It looks like this patchset fell through the cracks (I found it while searching for
something else).  A version of this patch went in, witout the HAVE_STRING_H ifdef.
Do you think the ifdef is necessary in practice?

Simon
  
Stafford Horne Jan. 27, 2019, 3:29 a.m. UTC | #2
On Tue, Jan 22, 2019 at 05:07:43PM +0000, Simon Marchi wrote:
> On 2018-12-02 8:05 a.m., Stafford Horne wrote:
> > I got this warning when building the OpenRISC sim target.
> > 
> > Warning:
> > 
> > In file included from ../../../binutils-gdb/sim/or1k/../common/cgen-trace.c:26:
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h: In function ‘next_disassembler_option’:
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: implicit declaration of function ‘strchr’ [-Wimplicit-function-declaration]
> >    const char *opt = strchr (options, ',');
> >                      ^~~~~~
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: warning: incompatible implicit declaration of built-in function ‘strchr’
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21: note: include ‘<string.h>’ or provide a declaration of ‘strchr’
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:40:1:
> > +#include <string.h>
> > 
> > ../../../binutils-gdb/sim/or1k/../../include/dis-asm.h:343:21:
> >    const char *opt = strchr (options, ',');
> >                      ^~~~~~
> > 
> > include/ChangeLog:
> > 
> > 	dis-asm.h: Include "string.h"
> > ---
> >  include/dis-asm.h | 4 ++++
> >  1 file changed, 4 insertions(+)
> > 
> > diff --git a/include/dis-asm.h b/include/dis-asm.h
> > index 84627950c0..823bba5b45 100644
> > --- a/include/dis-asm.h
> > +++ b/include/dis-asm.h
> > @@ -32,6 +32,10 @@ extern "C" {
> >  #endif
> >  
> >  #include <stdio.h>
> > +/* For strchr.  */
> > +#ifdef HAVE_STRING_H
> > +#include <string.h>
> > +#endif
> >  #include "bfd.h"
> >  
> >    typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;
> > 
> 
> Hi Stafford,
> 
> It looks like this patchset fell through the cracks (I found it while searching for
> something else).  A version of this patch went in, witout the HAVE_STRING_H ifdef.
> Do you think the ifdef is necessary in practice?

Sorry for the late reply, I just got back from vacation with the family in
Hawaii :).

I thought about this when I made this patch, we currently have a lot of these
HAVE_XXX_H checks throughout the sim code.  I am not sure of the history, but
perhaps I can try a patch set to eliminate a few of them like HAVE_STRING_H vs
HAVE_STRINGS_H (BSD).  I would think everything we need is in on every machine
in <string.h>.

I am not an expert in C/C++ compatibility.  Is there at minimum standard c/c++
required for gdb?  Perhaps this has changed since we moved to allow C++.

-Stafford
  
Tom Tromey Feb. 12, 2019, 9:55 p.m. UTC | #3
>>>>> "Stafford" == Stafford Horne <shorne@gmail.com> writes:

I didn't see a reply to this, apologies if I missed it somehow.

Stafford> I thought about this when I made this patch, we currently have a lot of these
Stafford> HAVE_XXX_H checks throughout the sim code.  I am not sure of the history, but
Stafford> perhaps I can try a patch set to eliminate a few of them like HAVE_STRING_H vs
Stafford> HAVE_STRINGS_H (BSD).  I would think everything we need is in on every machine
Stafford> in <string.h>.

The old BSD one is surely long obsolete.

The sim could also consider using gnulib.  This isn't totally trivial --
we'd probably have to move it to the top level, though I've wanted us to
do that for a while now -- but it would mean not having to care so much
about checking for standard headers.

Stafford> I am not an expert in C/C++ compatibility.  Is there at minimum standard c/c++
Stafford> required for gdb?  Perhaps this has changed since we moved to allow C++.

gdb uses C++11.  The rest of the tree uses C89 as far as I know.

Tom
  

Patch

diff --git a/include/dis-asm.h b/include/dis-asm.h
index 84627950c0..823bba5b45 100644
--- a/include/dis-asm.h
+++ b/include/dis-asm.h
@@ -32,6 +32,10 @@  extern "C" {
 #endif
 
 #include <stdio.h>
+/* For strchr.  */
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
 #include "bfd.h"
 
   typedef int (*fprintf_ftype) (void *, const char*, ...) ATTRIBUTE_FPTR_PRINTF_2;