diff --git a/libcxx/include/locale b/libcxx/include/locale --- a/libcxx/include/locale +++ b/libcxx/include/locale @@ -3455,7 +3455,7 @@ class _LIBCPP_EXPORTED_FROM_ABI messages_base { public: - typedef ptrdiff_t catalog; + typedef intptr_t catalog; _LIBCPP_INLINE_VISIBILITY messages_base() {} }; @@ -3512,10 +3512,7 @@ messages<_CharT>::do_open(const basic_string& __nm, const locale&) const { #ifdef _LIBCPP_HAS_CATOPEN - catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); - if (__cat != -1) - __cat = static_cast((static_cast(__cat) >> 1)); - return __cat; + return (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE); #else // !_LIBCPP_HAS_CATOPEN (void)__nm; return -1; @@ -3532,9 +3529,8 @@ __narrow_to_utf8()(std::back_inserter(__ndflt), __dflt.c_str(), __dflt.c_str() + __dflt.size()); - if (__c != -1) - __c <<= 1; nl_catd __cat = (nl_catd)__c; + static_assert(sizeof(catalog) >= sizeof(nl_catd), "Unexpected nl_catd type"); char* __n = catgets(__cat, __set, __msgid, __ndflt.c_str()); string_type __w; __widen_from_utf8()(std::back_inserter(__w), @@ -3553,10 +3549,7 @@ messages<_CharT>::do_close(catalog __c) const { #ifdef _LIBCPP_HAS_CATOPEN - if (__c != -1) - __c <<= 1; - nl_catd __cat = (nl_catd)__c; - catclose(__cat); + catclose((nl_catd)__c); #else // !_LIBCPP_HAS_CATOPEN (void)__c; #endif // _LIBCPP_HAS_CATOPEN diff --git a/libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp b/libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp --- a/libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp +++ b/libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp @@ -14,14 +14,22 @@ // typedef unspecified catalog; // }; +#include #include #include -#include "test_macros.h" +#include "assert_macros.h" -int main(int, char**) -{ - std::messages_base mb; +#ifdef _LIBCPP_VERSION +ASSERT_SAME_TYPE(std::messages_base::catalog, std::intptr_t); +#endif + +// Check that we implement LWG2028 +static_assert(std::is_signed::value, ""); +static_assert(std::is_integral::value, ""); + +int main(int, char**) { + std::messages_base mb; return 0; }