[libcxx-commits] [PATCH] D134420: [libc++] Use intptr_t instead of ptrdiff_t for messages_base::catalog

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Sep 7 08:39:23 PDT 2023


ldionne updated this revision to Diff 556161.
ldionne marked 5 inline comments as done.
ldionne added a comment.

Address comments and rebase.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134420/new/

https://reviews.llvm.org/D134420

Files:
  libcxx/include/locale
  libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp


Index: libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp
===================================================================
--- libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp
+++ libcxx/test/std/localization/locale.categories/category.messages/locale.messages/messages_base.pass.cpp
@@ -14,14 +14,22 @@
 //     typedef unspecified catalog;
 // };
 
+#include <cstdint>
 #include <locale>
 #include <type_traits>
 
-#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<std::messages_base::catalog>::value, "");
+static_assert(std::is_integral<std::messages_base::catalog>::value, "");
+
+int main(int, char**) {
+  std::messages_base mb;
 
   return 0;
 }
Index: libcxx/include/locale
===================================================================
--- libcxx/include/locale
+++ 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<char>& __nm, const locale&) const
 {
 #ifdef _LIBCPP_HAS_CATOPEN
-    catalog __cat = (catalog)catopen(__nm.c_str(), NL_CAT_LOCALE);
-    if (__cat != -1)
-        __cat = static_cast<catalog>((static_cast<size_t>(__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<sizeof(char_type)*__CHAR_BIT__>()(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<sizeof(char_type)*__CHAR_BIT__>()(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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134420.556161.patch
Type: text/x-patch
Size: 2676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230907/a819cfa4/attachment.bin>


More information about the libcxx-commits mailing list