When creating a gnulib testdir for module 'strerror'
  ./gnulib-tool --create-testdir --with-c++-tests --with-tests --dir=... 
strerror
and forcing REPLACE_STRERROR=1, the compilation in C++ mode with 
GNULIB_NAMESPACE
fails:

$ ./configure CPPFLAGS="-DGNULIB_NAMESPACE=gggg -Wall" CC=g++
$ make
...
g++ -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1 
-DGNULIB_NAMESPACE=gggg -Wall  -g -O2 -MT strerror.o -MD -MP -MF 
.deps/strerror.Tpo -c -o strerror.o strerror.c
strerror.c: In function 'char* rpl_strerror(int)':
strerror.c:70:35: error: invalid conversion from 'void*' to 'char*' 
[-fpermissive]
make[4]: *** [strerror.o] Error 1

The reason is that memcpy() returns a 'void *'. But we want a 'char *' here.
Rather than introduce a cast, simply use the known return value of memcpy().

I'm pushing this fix:


2016-11-19  Bruno Haible  <br...@clisp.org>

        strerror: Make it compile in C++ mode.
        * lib/strerror.c (strerror): Ignore the return value of memcpy().

--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -66,5 +66,6 @@ strerror (int n)
   if (sizeof buf <= len)
     abort ();
 
-  return memcpy (buf, msg, len + 1);
+  memcpy (buf, msg, len + 1);
+  return buf;
 }


Reply via email to