On Sat, Dec 28, 2019 at 04:40:54PM -0800, Philip Guenther wrote: > On Sat, 28 Dec 2019, Jonathan Gray wrote: > > On Sat, Dec 28, 2019 at 05:08:51PM -0500, Thomas Dickey wrote: > > > On Thu, Dec 26, 2019 at 05:12:56PM -0500, Thomas Dickey wrote: > ... > > > That's okay. But there's an error in OpenBSD's header files which > > > I'll have to work around for the time being. It would be nice if > > > someone fixed it: > > > > > > /usr/include/ctype.h has > > > > > > #if __POSIX_VISIBLE >= 200809 > > > #ifndef _LOCALE_T_DEFINED_ > > > #define _LOCALE_T_DEFINED_ > > > typedef void *locale_t; > > > #endif > > > #endif > > > > > > and (since ncurses uses no feature newer than this) my default build > > > does this: > > > > > > -D_BSD_SOURCE -D_XOPEN_SOURCE=600 > > > > defining _XOPEN_SOURCE=600 results in __POSIX_VISIBLE 200112 > > defining _XOPEN_SOURCE=700 results in __POSIX_VISIBLE 200809 > > when not defining anything you'll get __POSIX_VISIBLE 200809 > > > > So if you want it to be visible either don't do any visibility > > defines, use _XOPEN_SOURCE=700 or _POSIX_C_SOURCE=200809. > > Thomas's point is that our c++ <iostream> unconditionally pulls in > <support/xlocale/__strtonum_fallback.h> and <__locale> and perhaps others > which unconditionally use locale_t, despite locale_t being conditionally > defined. > > So, when did C++ start permitting and/or requiring locale_t to be > provided? > > One or more of these is presumably then true: > a) our C++ headers need #if's to skip all locale_t stuff when you select > an environment before locale_t was added > b) our <ctype.h> header needs to broaden its conditional to go ahead and > provide locale_t (and the functions?) when in a C++ environment that > should have them
It would appear that locale_t is not part of a C++ standard but libc++ assumes it exists and has fallbacks if it doesn't. Index: __bsd_locale_fallbacks.h =================================================================== RCS file: /cvs/src/lib/libcxx/include/__bsd_locale_fallbacks.h,v retrieving revision 1.1.1.3 diff -u -p -r1.1.1.3 __bsd_locale_fallbacks.h --- __bsd_locale_fallbacks.h 4 Feb 2019 16:55:45 -0000 1.1.1.3 +++ __bsd_locale_fallbacks.h 29 Dec 2019 02:46:31 -0000 @@ -45,6 +45,7 @@ int __libcpp_wctob_l(wint_t __c, locale_ return wctob(__c); } +#if __POSIX_VISIBLE >= 200809 inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_wcsnrtombs_l(char *__dest, const wchar_t **__src, size_t __nwc, size_t __len, mbstate_t *__ps, locale_t __l) @@ -52,6 +53,7 @@ size_t __libcpp_wcsnrtombs_l(char *__des __libcpp_locale_guard __current(__l); return wcsnrtombs(__dest, __src, __nwc, __len, __ps); } +#endif inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_wcrtomb_l(char *__s, wchar_t __wc, mbstate_t *__ps, locale_t __l) @@ -60,6 +62,7 @@ size_t __libcpp_wcrtomb_l(char *__s, wch return wcrtomb(__s, __wc, __ps); } +#if __POSIX_VISIBLE >= 200809 inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_mbsnrtowcs_l(wchar_t * __dest, const char **__src, size_t __nms, size_t __len, mbstate_t *__ps, locale_t __l) @@ -67,6 +70,7 @@ size_t __libcpp_mbsnrtowcs_l(wchar_t * _ __libcpp_locale_guard __current(__l); return mbsnrtowcs(__dest, __src, __nms, __len, __ps); } +#endif inline _LIBCPP_INLINE_VISIBILITY size_t __libcpp_mbrtowc_l(wchar_t *__pwc, const char *__s, size_t __n, Index: __locale =================================================================== RCS file: /cvs/src/lib/libcxx/include/__locale,v retrieving revision 1.5 diff -u -p -r1.5 __locale --- __locale 17 Jun 2019 22:28:51 -0000 1.5 +++ __locale 29 Dec 2019 02:01:06 -0000 @@ -28,8 +28,10 @@ #elif defined(__sun__) # include <xlocale.h> # include <support/solaris/xlocale.h> -#elif defined(_NEWLIB_VERSION) || defined(__OpenBSD__) +#elif defined(_NEWLIB_VERSION) # include <support/newlib/xlocale.h> +#elif defined(__OpenBSD__) +# include <support/openbsd/xlocale.h> #elif (defined(__APPLE__) || defined(__FreeBSD__) \ || defined(__EMSCRIPTEN__) || defined(__IBMCPP__)) # include <xlocale.h> Index: support/newlib/xlocale.h =================================================================== RCS file: /cvs/src/lib/libcxx/include/support/newlib/xlocale.h,v retrieving revision 1.5 diff -u -p -r1.5 xlocale.h --- support/newlib/xlocale.h 4 Feb 2019 17:04:36 -0000 1.5 +++ support/newlib/xlocale.h 29 Dec 2019 02:51:50 -0000 @@ -10,20 +10,18 @@ #ifndef _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H #define _LIBCPP_SUPPORT_NEWLIB_XLOCALE_H -#if defined(_NEWLIB_VERSION) || defined(__OpenBSD__) +#if defined(_NEWLIB_VERSION) #include <cstdlib> #include <clocale> #include <cwctype> #include <ctype.h> -#if !defined(__OpenBSD__) #if !defined(__NEWLIB__) || __NEWLIB__ < 2 || \ __NEWLIB__ == 2 && __NEWLIB_MINOR__ < 5 #include <support/xlocale/__nop_locale_mgmt.h> #include <support/xlocale/__posix_l_fallback.h> -#endif -#endif #include <support/xlocale/__strtonum_fallback.h> +#endif #endif // _NEWLIB_VERSION Index: support/openbsd/xlocale.h =================================================================== RCS file: support/openbsd/xlocale.h diff -N support/openbsd/xlocale.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ support/openbsd/xlocale.h 29 Dec 2019 02:39:43 -0000 @@ -0,0 +1,30 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is dual licensed under the MIT and the University of Illinois Open +// Source Licenses. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_OPENBSD_XLOCALE_H +#define _LIBCPP_SUPPORT_OPENBSD_XLOCALE_H + +#if defined(__OpenBSD__) + +#include <cstdlib> +#include <clocale> +#include <cwctype> +#include <ctype.h> + +/* libc++ assumes POSIX 2008 locale_t */ +#if __POSIX_VISIBLE < 200809 +#include <support/xlocale/__nop_locale_mgmt.h> +#include <support/xlocale/__posix_l_fallback.h> +#endif + +#include <support/xlocale/__strtonum_fallback.h> + +#endif // __OpenBSD__ + +#endif