bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

strtol, strtoul: Fix compilation error in C++ mode on Solaris 11


From: Bruno Haible
Subject: strtol, strtoul: Fix compilation error in C++ mode on Solaris 11
Date: Fri, 02 Sep 2022 20:37:38 +0200

A gnulib testdir also produces these compilation errors on Solaris 11 OmniOS:

../gllib/stdlib.h:1918:1: error: 'long int strtol(const char*, char**, int)' 
conflicts with a previous declaration
 1918 | _GL_CXXALIASWARN (strtol);
      | ^~~~~~~~~~~~~~~~
In file included from /usr/include/stdlib.h:40,
                 from /opt/gcc-9/include/c++/9.3.0/cstdlib:75,
                 from /opt/gcc-9/include/c++/9.3.0/stdlib.h:36,
                 from ../gllib/stdlib.h:36,
                 from ../gllib/malloc.h:35,
                 from ../../gltests/test-malloc-h-c++.cc:22:
/usr/include/iso/stdlib_iso.h:157:17: note: previous declaration 'long int 
std::strtol(const char*, char**, int)'
  157 | extern long int strtol(const char *_RESTRICT_KYWD, char 
**_RESTRICT_KYWD, int);
      |                 ^~~~~~
In file included from /usr/include/sys/time.h:489,
                 from ../gllib/sys/time.h:39,
                 from /usr/include/sys/select.h:53,
                 from ../gllib/sys/select.h:36,
                 from /usr/include/sys/types.h:640,
                 from ../gllib/sys/types.h:39,
                 from /usr/include/malloc.h:31,
                 from ../gllib/malloc.h:27,
                 from ../../gltests/test-malloc-h-c++.cc:22:
../gllib/stdlib.h:1999:1: error: 'long unsigned int strtoul(const char*, 
char**, int)' conflicts with a previous declaration
 1999 | _GL_CXXALIASWARN (strtoul);
      | ^~~~~~~~~~~~~~~~
In file included from /usr/include/stdlib.h:40,
                 from /opt/gcc-9/include/c++/9.3.0/cstdlib:75,
                 from /opt/gcc-9/include/c++/9.3.0/stdlib.h:36,
                 from ../gllib/stdlib.h:36,
                 from ../gllib/malloc.h:35,
                 from ../../gltests/test-malloc-h-c++.cc:22:
/usr/include/iso/stdlib_iso.h:158:26: note: previous declaration 'long unsigned 
int std::strtoul(const char*, char**, int)'
  158 | extern unsigned long int strtoul(const char *_RESTRICT_KYWD,
      |                          ^~~~~~~
gmake[4]: *** [Makefile:23194: test-malloc-h-c++.o] Error 1


It looks like 'restrict' in the declaration makes a difference in C++.
This patch fixes it.


2022-09-02  Bruno Haible  <bruno@clisp.org>

        strtol, strtoul: Fix compilation error in C++ mode on Solaris 11.
        * lib/stdlib.in.h (strtol, strtoul): Enable the C++ alias warning only
        on glibc systems.

diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 010875803c..8e0a609f1f 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -1363,7 +1363,9 @@ _GL_CXXALIAS_SYS (strtol, long,
                   (const char *restrict string, char **restrict endptr,
                    int base));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (strtol);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef strtol
 # if HAVE_RAW_DECL_STRTOL
@@ -1444,7 +1446,9 @@ _GL_CXXALIAS_SYS (strtoul, unsigned long,
                   (const char *restrict string, char **restrict endptr,
                    int base));
 # endif
+# if __GLIBC__ >= 2
 _GL_CXXALIASWARN (strtoul);
+# endif
 #elif defined GNULIB_POSIXCHECK
 # undef strtoul
 # if HAVE_RAW_DECL_STRTOUL






reply via email to

[Prev in Thread] Current Thread [Next in Thread]