[libcxx-commits] [PATCH] D120802: [libcxx] [test] Fix the classic_table test on Windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 2 01:29:08 PST 2022


mstorsjo created this revision.
mstorsjo added reviewers: Mordante, Quuxplusone.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: libc++.
Herald added a reviewer: libc++.

Whether we can check for e.g. `F::alpha` and `F::print` corresponds
to the `_LIBCPP_CTYPE_MASK_IS_COMPOSITE_PRINT` and
`_LIBCPP_CTYPE_MASK_IS_COMPOSITE_ALPHA` defines - but we can't check
those in a standard test.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120802

Files:
  libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.statics/classic_table.pass.cpp


Index: libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.statics/classic_table.pass.cpp
===================================================================
--- libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.statics/classic_table.pass.cpp
+++ libcxx/test/std/localization/locale.categories/category.ctype/facet.ctype.special/facet.ctype.char.statics/classic_table.pass.cpp
@@ -12,8 +12,6 @@
 
 // static const mask* classic_table() throw();
 
-// XFAIL: LIBCXX-WINDOWS-FIXME
-
 #include <locale>
 #include <cassert>
 
@@ -29,19 +27,29 @@
     const mask *p = F::classic_table();
     const mask defined = F::space | F::print | F::cntrl | F::upper | F::lower
                     | F::alpha | F::digit | F::punct | F::xdigit | F::blank;
+#ifdef _WIN32
+    // On Windows, the alpha and print masks aren't individual bits that
+    // are set, but are only usable as masks, as they are combinations of
+    // the bits for upper/lower/digit/blank/punct.
+    const mask bit_alpha = 0;
+    const mask bit_print = 0;
+#else
+    const mask bit_alpha = F::alpha;
+    const mask bit_print = F::print;
+#endif
 
     for ( size_t i = 0; i < 128; ++i ) // values above 128 are not consistent
     {
         mask set = 0;
 
         if ( i  < 32  || i  > 126 ) set |= F::cntrl;
-        if ( i >= 32  && i <= 126 ) set |= F::print;
+        if ( i >= 32  && i <= 126 ) set |= bit_print;
 
         if (( i >= 9 && i <= 13) || i == 32 ) set |= F::space;
         if ( i == 9 || i == 32 ) set |= F::blank;
 
-        if ( i >= 'A' && i <= 'Z' ) set |= F::alpha;
-        if ( i >= 'a' && i <= 'z' ) set |= F::alpha;
+        if ( i >= 'A' && i <= 'Z' ) set |= bit_alpha;
+        if ( i >= 'a' && i <= 'z' ) set |= bit_alpha;
         if ( i >= 'A' && i <= 'Z' ) set |= F::upper;
         if ( i >= 'a' && i <= 'z' ) set |= F::lower;
 
@@ -55,6 +63,14 @@
         if ( i >=  91 && i <=  96 ) set |= F::punct;    // '[' .. '`'
         if ( i >= 123 && i <= 126 ) set |= F::punct;    // '{' .. '~'    }
 
+#ifdef _WIN32
+        // The underlying Windows __pctype_func() table doesn't have the blank
+        // bit set for horizontal tab (9). The Windows CRT implementation of
+        // the isblank() function instead has a special case check for the
+        // horizontal tab character.
+        if (i == 9) set &= ~F::blank;
+#endif
+
         assert(( p[i] &  set) == set);            // all the right bits set
         assert(((p[i] & ~set) & defined) == 0);   // no extra ones
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120802.412353.patch
Type: text/x-patch
Size: 2584 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220302/d5c5ebcb/attachment-0001.bin>


More information about the libcxx-commits mailing list