On Solaris 11.3, a testdir produces these compilation errors: * With Sun C/C++:
source='../../gltests/test-wchar-c++.cc' object='test-wchar-c++.o' libtool=no \ DEPDIR=.deps depmode=none /bin/sh ../../build-aux/depcomp \ CC -m64 -O -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/export/home/haible/prefix-sparc64/include -D_REENTRANT -g -c -o test-wchar-c++.o ../../gltests/test-wchar-c++.cc "../gllib/wchar.h", line 1259: Error: wcsnlen is not defined. "../gllib/wchar.h", line 1297: Error: wcpcpy is not defined. "../gllib/wchar.h", line 1340: Error: wcpncpy is not defined. "../gllib/wchar.h", line 1439: Error: wcscasecmp is not defined. "../gllib/wchar.h", line 1458: Error: wcsncasecmp is not defined. "../gllib/wchar.h", line 1524: Error: wcsdup is not defined. 6 Error(s) and 135 Warning(s) detected. gmake[4]: *** [Makefile:23350: test-wchar-c++.o] Error 2 * With gcc/g++: depbase=`echo test-wchar-c++.o | sed 's|[^/]*$|.deps/&|;s|\.o$||'`;\ g++ -m64 -O2 -DHAVE_CONFIG_H -DEXEEXT=\"\" -I. -I../../gltests -I.. -DGNULIB_STRICT_CHECKING=1 -DIN_GNULIB_TESTS=1 -I. -I../../gltests -I.. -I../../gltests/.. -I../gllib -I../../gltests/../gllib -I/export/home/haible/prefix-sparc64/include -Wall -D_REENTRANT -I/opt/csw/include -Wno-error -g -O2 -MT test-wchar-c++.o -MD -MP -MF $depbase.Tpo -c -o test-wchar-c++.o ../../gltests/test-wchar-c++.cc &&\ mv -f $depbase.Tpo $depbase.Po In file included from /usr/include/sys/time.h:480:0, from ../gllib/sys/time.h:39, from /usr/include/sys/select.h:28, from ../gllib/sys/select.h:36, from /usr/include/sys/types.h:664, from ../gllib/sys/types.h:39, from ../gllib/stdio.h:58, from /usr/include/iso/wchar_iso.h:28, from /opt/csw/lib/gcc/sparc-sun-solaris2.10/5.5.0/include-fixed/wchar.h:22, from ../gllib/wchar.h:80, from ../../gltests/test-wchar-c++.cc:22: ../gllib/wchar.h: In member function 'gnulib::_gl_wcsnlen_wrapper::operator gnulib::_gl_wcsnlen_wrapper::type() const': ../gllib/wchar.h:1259:1: error: '::wcsnlen' has not been declared _GL_CXXALIAS_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen)); ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1260:1: error: 'wcsnlen' was not declared in this scope _GL_CXXALIASWARN (wcsnlen); ^ ../gllib/wchar.h:1260:1: note: suggested alternative: ../gllib/wchar.h:1259:1: note: 'gnulib::wcsnlen' _GL_CXXALIAS_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen)); ^ ../gllib/wchar.h: In member function 'gnulib::_gl_wcpcpy_wrapper::operator gnulib::_gl_wcpcpy_wrapper::type() const': ../gllib/wchar.h:1296:1: error: '::wcpcpy' has not been declared _GL_CXXALIAS_SYS (wcpcpy, wchar_t *, ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1298:1: error: 'wcpcpy' was not declared in this scope _GL_CXXALIASWARN (wcpcpy); ^ ../gllib/wchar.h:1298:1: note: suggested alternative: ../gllib/wchar.h:1296:1: note: 'gnulib::wcpcpy' _GL_CXXALIAS_SYS (wcpcpy, wchar_t *, ^ ../gllib/wchar.h: In member function 'gnulib::_gl_wcpncpy_wrapper::operator gnulib::_gl_wcpncpy_wrapper::type() const': ../gllib/wchar.h:1338:1: error: '::wcpncpy' has not been declared _GL_CXXALIAS_SYS (wcpncpy, wchar_t *, ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1341:1: error: 'wcpncpy' was not declared in this scope _GL_CXXALIASWARN (wcpncpy); ^ ../gllib/wchar.h:1341:1: note: suggested alternative: ../gllib/wchar.h:1338:1: note: 'gnulib::wcpncpy' _GL_CXXALIAS_SYS (wcpncpy, wchar_t *, ^ ../gllib/wchar.h: In member function 'gnulib::_gl_wcscasecmp_wrapper::operator gnulib::_gl_wcscasecmp_wrapper::type() const': ../gllib/wchar.h:1439:1: error: '::wcscasecmp' has not been declared _GL_CXXALIAS_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2)); ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1440:1: error: 'wcscasecmp' was not declared in this scope _GL_CXXALIASWARN (wcscasecmp); ^ ../gllib/wchar.h:1440:1: note: suggested alternative: ../gllib/wchar.h:1439:1: note: 'gnulib::wcscasecmp' _GL_CXXALIAS_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2)); ^ ../gllib/wchar.h: In member function 'gnulib::_gl_wcsncasecmp_wrapper::operator gnulib::_gl_wcsncasecmp_wrapper::type() const': ../gllib/wchar.h:1457:1: error: '::wcsncasecmp' has not been declared _GL_CXXALIAS_SYS (wcsncasecmp, int, ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1459:1: error: 'wcsncasecmp' was not declared in this scope _GL_CXXALIASWARN (wcsncasecmp); ^ ../gllib/wchar.h:1459:1: note: suggested alternative: ../gllib/wchar.h:1457:1: note: 'gnulib::wcsncasecmp' _GL_CXXALIAS_SYS (wcsncasecmp, int, ^ ../gllib/wchar.h: In member function 'gnulib::_gl_wcsdup_wrapper::operator gnulib::_gl_wcsdup_wrapper::type() const': ../gllib/wchar.h:1524:1: error: '::wcsdup' has not been declared _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); ^ ../gllib/wchar.h: At global scope: ../gllib/wchar.h:1526:1: error: 'wcsdup' was not declared in this scope _GL_CXXALIASWARN (wcsdup); ^ ../gllib/wchar.h:1526:1: note: suggested alternative: ../gllib/wchar.h:1524:1: note: 'gnulib::wcsdup' _GL_CXXALIAS_SYS (wcsdup, wchar_t *, (const wchar_t *s)); ^ gmake[4]: *** [Makefile:23347: test-wchar-c++.o] Error 1 The cause is that on this platform, the functions wcsnlen, wcpcpy, etc. are declared inside namespace std { ... } But to make our _GL_CXXALIAS_SYS macros work, we need the declaration in the global namespace. There are two ways to achieve this: (a) through a 'using std::wcsnlen;' declaration, (b) by providing a declaration in the global namespace ourselves. I think (b) will lead to fewer problems than (a), regarding different Solaris versions. Therefore that's the solution I choose. 2022-09-17 Bruno Haible <br...@clisp.org> wchar: Fix compilation errors in C++ mode on Solaris 11.3. * lib/wchar.in.h (wcsnlen, wcpcpy, wcpncpy, wcscasecmp, wcsncasecmp, wcsdup): Force declaration in C++ mode on Solaris (which does not declare these functions in the global namespace). diff --git a/lib/wchar.in.h b/lib/wchar.in.h index 835ddbe659..3558adfb9d 100644 --- a/lib/wchar.in.h +++ b/lib/wchar.in.h @@ -745,7 +745,10 @@ _GL_WARN_ON_USE (wcslen, "wcslen is unportable - " /* Return the number of wide characters in S, but at most MAXLEN. */ #if @GNULIB_WCSNLEN@ -# if !@HAVE_WCSNLEN@ +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCSNLEN@ || (defined __sun && defined __cplusplus) _GL_FUNCDECL_SYS (wcsnlen, size_t, (const wchar_t *s, size_t maxlen) _GL_ATTRIBUTE_PURE); # endif @@ -782,7 +785,10 @@ _GL_WARN_ON_USE (wcscpy, "wcscpy is unportable - " /* Copy SRC to DEST, returning the address of the terminating L'\0' in DEST. */ #if @GNULIB_WCPCPY@ -# if !@HAVE_WCPCPY@ +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCPCPY@ || (defined __sun && defined __cplusplus) _GL_FUNCDECL_SYS (wcpcpy, wchar_t *, (wchar_t *restrict dest, const wchar_t *restrict src)); # endif @@ -823,7 +829,10 @@ _GL_WARN_ON_USE (wcsncpy, "wcsncpy is unportable - " /* Copy no more than N characters of SRC to DEST, returning the address of the last character written into DEST. */ #if @GNULIB_WCPNCPY@ -# if !@HAVE_WCPNCPY@ +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCPNCPY@ || (defined __sun && defined __cplusplus) _GL_FUNCDECL_SYS (wcpncpy, wchar_t *, (wchar_t *restrict dest, const wchar_t *restrict src, size_t n)); @@ -925,7 +934,10 @@ _GL_WARN_ON_USE (wcsncmp, "wcsncmp is unportable - " /* Compare S1 and S2, ignoring case. */ #if @GNULIB_WCSCASECMP@ -# if !@HAVE_WCSCASECMP@ +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCSCASECMP@ || (defined __sun && defined __cplusplus) _GL_FUNCDECL_SYS (wcscasecmp, int, (const wchar_t *s1, const wchar_t *s2) _GL_ATTRIBUTE_PURE); # endif @@ -942,7 +954,10 @@ _GL_WARN_ON_USE (wcscasecmp, "wcscasecmp is unportable - " /* Compare no more than N chars of S1 and S2, ignoring case. */ #if @GNULIB_WCSNCASECMP@ -# if !@HAVE_WCSNCASECMP@ +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCSNCASECMP@ || (defined __sun && defined __cplusplus) _GL_FUNCDECL_SYS (wcsncasecmp, int, (const wchar_t *s1, const wchar_t *s2, size_t n) _GL_ATTRIBUTE_PURE); @@ -1009,7 +1024,10 @@ _GL_WARN_ON_USE (wcsxfrm, "wcsxfrm is unportable - " # endif _GL_CXXALIAS_MDA (wcsdup, wchar_t *, (const wchar_t *s)); # else -# if !@HAVE_WCSDUP@ || __GNUC__ >= 11 +/* On Solaris 11.3, the header files declare the function in the std:: + namespace, not in the global namespace. So, force a declaration in + the global namespace. */ +# if !@HAVE_WCSDUP@ || (defined __sun && defined __cplusplus) || __GNUC__ >= 11 _GL_FUNCDECL_SYS (wcsdup, wchar_t *, (const wchar_t *s) _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE);