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

2022-09-02 Thread Bruno Haible
Paul Eggert wrote:
> > +# if __GLIBC__ >= 2
> >   _GL_CXXALIASWARN (strtol);
> > +# endif
> 
> Would it make sense to move the __GLIBC__ >= 2 check into 
> _GL_CXXALIASWARN so that we needn't worry about making these sorts of 
> patches? How much benefit to non-glibc ports do we obtain from requiring 
> each _GL_CXXALIASWARN caller to decide whether to worry about __GLIBC__?

It would save us a a few patches occasionally. But it's only a minority
of the C++ related compilation failures. Looking in the ChangeLog,
C++ compilation failures have different causes:
  - _GL_CXXALIASWARN with undefined functions,
  - _GL_CXXALIASWARN with differences in 'restrict',
  - _GL_CXXALIASWARN with slightly different function signature,
  - exception specifications,
  - overloaded functions (w.r.t. 'const'),
  - linkage.

Not all developers develop on glibc systems. Just read a comment by a user
today [1]: "My phone runs Linux. My GF's phone runs Linux. My TV runs Linux,
too. So does the TV box-set (cable provider),  And I say this as a
desktop OpenBSD user."

So, unless it's really too much effort to keep most of these
_GL_CXXALIASWARN invocations enabled almost everywhere, I'd like to keep them.

Bruno

[1] https://news.ycombinator.com/item?id=26451540






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

2022-09-02 Thread Paul Eggert

On 9/2/22 13:37, Bruno Haible wrote:

+# if __GLIBC__ >= 2
  _GL_CXXALIASWARN (strtol);
+# endif


Would it make sense to move the __GLIBC__ >= 2 check into 
_GL_CXXALIASWARN so that we needn't worry about making these sorts of 
patches? How much benefit to non-glibc ports do we obtain from requiring 
each _GL_CXXALIASWARN caller to decide whether to worry about __GLIBC__?





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

2022-09-02 Thread Bruno Haible
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  

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