Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions stl/inc/xlocale
Original file line number Diff line number Diff line change
Expand Up @@ -2369,25 +2369,29 @@ _STL_RESTORE_DEPRECATED_WARNING
#define _UP _UPPER // 'A'-'Z'
#define _XD _HEX // '0'-'9', 'A'-'F', 'a'-'f'

_EXPORT_STD extern "C++" struct _CRTIMP2_PURE_IMPORT ctype_base // base for ctype
: locale::facet // TRANSITION, ABI, shouldn't be derived from locale::facet
{
enum { // constants for character classifications
alnum = _DI | _LO | _UP | _XA,
alpha = _LO | _UP | _XA,
cntrl = _BB,
digit = _DI,
graph = _DI | _LO | _PU | _UP | _XA,
lower = _LO,
print = _DI | _LO | _PU | _SP | _UP | _XA | _XD,
punct = _PU,
space = _CN | _SP,
upper = _UP,
xdigit = _XD,
blank = _CN | _SP
};
struct _Ctype_constants_base {
using mask = short; // to match <ctype.h>

// constants for character classifications

static constexpr mask alnum = _DI | _LO | _UP | _XA;
static constexpr mask alpha = _LO | _UP | _XA;
static constexpr mask cntrl = _BB;
static constexpr mask digit = _DI;
static constexpr mask graph = _DI | _LO | _PU | _UP | _XA;
static constexpr mask lower = _LO;
static constexpr mask print = _DI | _LO | _PU | _SP | _UP | _XA | _XD;
static constexpr mask punct = _PU;
static constexpr mask space = _CN | _SP;
static constexpr mask upper = _UP;
static constexpr mask xdigit = _XD;
static constexpr mask blank = _CN | _SP;
};

_EXPORT_STD extern "C++" struct _CRTIMP2_PURE_IMPORT ctype_base // base for ctype
: locale::facet, // TRANSITION, ABI, shouldn't be derived from locale::facet
_Ctype_constants_base // TRANSITION, ABI, avoid affecting DLL interface
{
__CLR_OR_THIS_CALL ctype_base(size_t _Refs = 0) noexcept // strengthened
: locale::facet(_Refs) {}

Expand Down
34 changes: 34 additions & 0 deletions tests/std/tests/Dev11_1074023_constexpr/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,12 @@ void test_all_constants() {

test_constants<ios_base::seekdir, ios_base::beg, ios_base::cur, ios_base::end>();

// LWG-4037 "Static data members of ctype_base are not yet required to be usable in constant expressions"
// The following furtherly requires ctype_base::mask to be usable as a type of a constant template parameter.
test_constants<ctype_base::mask, ctype_base::alnum, ctype_base::alpha, ctype_base::cntrl, ctype_base::digit,
ctype_base::graph, ctype_base::lower, ctype_base::print, ctype_base::punct, ctype_base::space,
ctype_base::upper, ctype_base::xdigit, ctype_base::blank>();

test_constants<RC::syntax_option_type, RC::icase, RC::nosubs, RC::optimize, RC::collate, RC::ECMAScript, RC::basic,
RC::extended, RC::awk, RC::grep, RC::egrep, regex::icase, regex::nosubs, regex::optimize, regex::collate,
regex::ECMAScript, regex::basic, regex::extended, regex::awk, regex::grep, regex::egrep>();
Expand All @@ -814,6 +820,34 @@ void test_all_constants() {
RC::error_badrepeat, RC::error_complexity, RC::error_stack>();
}

// Ensure that these members of ctype_base are actually implemented as static const members of the correct type.

STATIC_ASSERT(is_same_v<decltype(ctype_base::alnum), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::alpha), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::cntrl), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::digit), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::graph), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::lower), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::print), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::punct), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::space), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::upper), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::xdigit), const ctype_base::mask>);
STATIC_ASSERT(is_same_v<decltype(ctype_base::blank), const ctype_base::mask>);

STATIC_ASSERT(is_same_v<decltype((ctype_base::alnum)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::alpha)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::cntrl)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::digit)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::graph)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::lower)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::print)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::punct)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::space)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::upper)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::xdigit)), const ctype_base::mask&>);
STATIC_ASSERT(is_same_v<decltype((ctype_base::blank)), const ctype_base::mask&>);

constexpr csub_match sm{};
STATIC_ASSERT(sm.first == nullptr);
STATIC_ASSERT(sm.second == nullptr);
Expand Down