[libcxx-commits] [PATCH] D63284: [libc++] Keep __regex_word in sync with ctype_base

Mikhail Maltsev via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jun 13 10:16:46 PDT 2019


miyuki created this revision.
miyuki added reviewers: ldionne, mclow.lists.
Herald added a reviewer: EricWF.
Herald added subscribers: dexonsmith, christof, krytarowski.
Herald added a project: libc++.

The class ctype_base in the header <__locale> contains masks for
character classification functions, which are kept in sync with
platform's C library, hence it contains many special cases.
The value of the bit mask __regex_word in the header <regex> must not
clash with those bit masks.

Currently the default case (i.e. unknown platform/C library) is
handled incorrectly: the __regex_word clashes with ctype_base::punct.

To avoid replicating the whole list of platforms in <regex> this patch
defines __regex_word in <__locale>, so that it is always kept in sync
with other masks.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63284

Files:
  libcxx/include/__locale
  libcxx/include/regex


Index: libcxx/include/regex
===================================================================
--- libcxx/include/regex
+++ libcxx/include/regex
@@ -1001,16 +1001,7 @@
     typedef locale                  locale_type;
     typedef ctype_base::mask        char_class_type;
 
-#if defined(__mips__) && defined(__GLIBC__)
-    static const char_class_type __regex_word = static_cast<char_class_type>(_ISbit(15));
-#elif defined(__NetBSD__)
-    // NetBSD defines classes up to 0x2000
-    // see sys/ctype_bits.h, _CTYPE_Q
-    static const char_class_type __regex_word = 0x8000;
-#else
-    static const char_class_type __regex_word = 0x80;
-#endif
-
+    static const char_class_type __regex_word = ctype_base::__regex_word;
 private:
     locale __loc_;
     const ctype<char_type>* __ct_;
Index: libcxx/include/__locale
===================================================================
--- libcxx/include/__locale
+++ libcxx/include/__locale
@@ -408,6 +408,11 @@
     static const mask punct  = _ISpunct;
     static const mask xdigit = _ISxdigit;
     static const mask blank  = _ISblank;
+#if defined(__mips__)
+    static const mask __regex_word = static_cast<char_class_type>(_ISbit(15));
+#else
+    static const mask __regex_word = 0x80;
+#endif
 #elif defined(_LIBCPP_MSVCRT_LIKE)
     typedef unsigned short mask;
     static const mask space  = _SPACE;
@@ -420,6 +425,7 @@
     static const mask punct  = _PUNCT;
     static const mask xdigit = _HEX;
     static const mask blank  = _BLANK;
+    static const mask __regex_word = 0x80;
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
 #elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__)
 # ifdef __APPLE__
@@ -441,8 +447,12 @@
 
 # if defined(__NetBSD__)
     static const mask blank  = _CTYPE_BL;
+    // NetBSD defines classes up to 0x2000
+    // see sys/ctype_bits.h, _CTYPE_Q
+    static const mask __regex_word = 0x8000;
 # else
     static const mask blank  = _CTYPE_B;
+    static const mask __regex_word = 0x80;
 # endif
 #elif defined(__sun__) || defined(_AIX)
     typedef unsigned int mask;
@@ -456,6 +466,7 @@
     static const mask punct  = _ISPUNCT;
     static const mask xdigit = _ISXDIGIT;
     static const mask blank  = _ISBLANK;
+    static const mask __regex_word = 0x80;
 #elif defined(_NEWLIB_VERSION)
     // Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
     typedef char mask;
@@ -469,6 +480,7 @@
     static const mask punct  = _P;
     static const mask xdigit = _X | _N;
     static const mask blank  = _B;
+    static const mask __regex_word = 0x80;
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA
 # define _LIBCPP_CTYPE_MASK_IS_COMPOSITE_XDIGIT
@@ -484,6 +496,7 @@
     static const mask punct  = 1<<7;
     static const mask xdigit = 1<<8;
     static const mask blank  = 1<<9;
+    static const mask __regex_word = 1<<10;
 #endif
     static const mask alnum  = alpha | digit;
     static const mask graph  = alnum | punct;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63284.204572.patch
Type: text/x-patch
Size: 3038 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20190613/86ffcfe8/attachment-0001.bin>


More information about the libcxx-commits mailing list