Skip to content
Merged
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
21 changes: 6 additions & 15 deletions stl/inc/xiosbase
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ _STL_DISABLE_CLANG_WARNINGS

_STD_BEGIN
template <class _Dummy>
class _Iosb { // define templatized bitmask/enumerated types, instantiate on demand
class _Iosb { // define templatized bitmask types, instantiate on demand
public:
enum _Fmtflags { // constants for formatting options
_Fmtmask = 0xffff,
_Fmtzero = 0
};
// constants for formatting options
static constexpr int _Fmtmask = 0xffff;
static constexpr int _Fmtzero = 0;

static constexpr int skipws = 0x0001;
static constexpr int unitbuf = 0x0002;
Expand All @@ -47,9 +46,8 @@ public:
static constexpr int basefield = dec | oct | hex;
static constexpr int floatfield = scientific | fixed;

enum _Iostate { // constants for stream states
_Statmask = 0x17
};
// constants for stream states
static constexpr int _Statmask = 0x17;

static constexpr int goodbit = 0x0;
static constexpr int eofbit = 0x1;
Expand All @@ -73,13 +71,6 @@ public:
static constexpr int end = 2;

static constexpr int _Default_open_prot = _SH_DENYNO; // constant for default file opening protection

// TRANSITION, ABI: These enums don't appear in the STL DLL's export surface, but MaxMPDCompat
// in the MSVC-internal build detects that they appear in the CompatibilityData baseline.
enum _Dummy_enum { _Dummy_enum_val = 1 };
enum _Openmode { _Openmask = 0xff };
enum _Seekdir { _Seekbeg, _Seekcur, _Seekend };
enum { _Openprot = _SH_DENYNO };
};

_EXPORT_STD extern "C++" class _CRTIMP2_PURE_IMPORT ios_base : public _Iosb<int> { // base class for ios
Expand Down
46 changes: 29 additions & 17 deletions stl/inc/xlocale
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ _STL_DISABLE_CLANG_WARNINGS
#pragma push_macro("new")
#undef new

// TRANSITION, non-_Ugly attribute tokens
#pragma push_macro("empty_bases")
#undef empty_bases

_STD_BEGIN
template <class _Dummy>
class _Locbase {}; // TRANSITION, ABI, affects sizeof(locale)
Expand Down Expand Up @@ -2373,25 +2377,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 __declspec(empty_bases) 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 Expand Up @@ -3312,6 +3320,10 @@ template class _CRTIMP2_PURE_IMPORT codecvt<char, char, mbstate_t>;
#endif // !defined(_CRTBLD) || defined(__FORCE_INSTANCE)
#endif // defined(_DLL_CPPLIB)
_STD_END

// TRANSITION, non-_Ugly attribute tokens
#pragma pop_macro("empty_bases")

#pragma pop_macro("new")
_STL_RESTORE_CLANG_WARNINGS
#pragma warning(pop)
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