From ea32e86deed6e8a8cd6116dc275e358a901d2b50 Mon Sep 17 00:00:00 2001 From: "Stephan T. Lavavej" Date: Wed, 15 Jun 2022 18:35:17 -0700 Subject: [PATCH] Mark constants as `_INLINE_VAR constexpr`. (#2792) --- stl/inc/functional | 2 +- stl/inc/regex | 16 ++++++++-------- stl/inc/vector | 5 +++-- stl/inc/xstring | 3 ++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/stl/inc/functional b/stl/inc/functional index 783433cd1..b3c0b8bed 100644 --- a/stl/inc/functional +++ b/stl/inc/functional @@ -722,7 +722,7 @@ private: virtual const void* _Get() const noexcept = 0; }; -constexpr size_t _Space_size = (_Small_object_num_ptrs - 1) * sizeof(void*); +_INLINE_VAR constexpr size_t _Space_size = (_Small_object_num_ptrs - 1) * sizeof(void*); template // determine whether _Impl must be dynamically allocated _INLINE_VAR constexpr bool _Is_large = sizeof(_Impl) > _Space_size || alignof(_Impl) > alignof(max_align_t) diff --git a/stl/inc/regex b/stl/inc/regex index b13d30b97..d84142b14 100644 --- a/stl/inc/regex +++ b/stl/inc/regex @@ -1155,16 +1155,16 @@ _NODISCARD bool operator!=(const match_results<_BidIt, _Alloc>& _Left, const mat } #endif // !_HAS_CXX20 -const unsigned int _BRE_MAX_GRP = 9U; +_INLINE_VAR constexpr unsigned int _BRE_MAX_GRP = 9U; -const unsigned int _Bmp_max = 256U; // must fit in an unsigned int -const unsigned int _Bmp_shift = 3U; -const unsigned int _Bmp_chrs = 1U << _Bmp_shift; // # of bits to be stored in each char -const unsigned int _Bmp_mask = _Bmp_chrs - 1U; -const unsigned int _Bmp_size = (_Bmp_max + _Bmp_chrs - 1U) / _Bmp_chrs; +_INLINE_VAR constexpr unsigned int _Bmp_max = 256U; // must fit in an unsigned int +_INLINE_VAR constexpr unsigned int _Bmp_shift = 3U; +_INLINE_VAR constexpr unsigned int _Bmp_chrs = 1U << _Bmp_shift; // # of bits to be stored in each char +_INLINE_VAR constexpr unsigned int _Bmp_mask = _Bmp_chrs - 1U; +_INLINE_VAR constexpr unsigned int _Bmp_size = (_Bmp_max + _Bmp_chrs - 1U) / _Bmp_chrs; -const unsigned int _Buf_incr = 16U; -const unsigned int _ARRAY_THRESHOLD = 4U; +_INLINE_VAR constexpr unsigned int _Buf_incr = 16U; +_INLINE_VAR constexpr unsigned int _ARRAY_THRESHOLD = 4U; enum _Node_flags : int { // flags for nfa nodes with special properties _Fl_none = 0x00, diff --git a/stl/inc/vector b/stl/inc/vector index d9d70aca7..de2e3a19c 100644 --- a/stl/inc/vector +++ b/stl/inc/vector @@ -2108,8 +2108,9 @@ vector(_Iter, _Iter, _Alloc = _Alloc()) -> vector<_Iter_value_t<_Iter>, _Alloc>; template class vector; -using _Vbase = unsigned int; // word type for vector representation -constexpr int _VBITS = 8 * sizeof(_Vbase); // at least CHAR_BITS bits per word +using _Vbase = unsigned int; // word type for vector representation + +_INLINE_VAR constexpr int _VBITS = 8 * sizeof(_Vbase); // at least CHAR_BITS bits per word template _NODISCARD _CONSTEXPR20 bool operator==(const vector<_Ty, _Alloc>& _Left, const vector<_Ty, _Alloc>& _Right) { diff --git a/stl/inc/xstring b/stl/inc/xstring index 395ec12ae..ff946f56a 100644 --- a/stl/inc/xstring +++ b/stl/inc/xstring @@ -2324,8 +2324,9 @@ public: size_type _Myres = 0; // current storage reserved for string }; +// get _Ty's size after being EBCO'd template -constexpr size_t _Size_after_ebco_v = is_empty_v<_Ty> ? 0 : sizeof(_Ty); // get _Ty's size after being EBCO'd +_INLINE_VAR constexpr size_t _Size_after_ebco_v = is_empty_v<_Ty> ? 0 : sizeof(_Ty); struct _String_constructor_concat_tag { // tag to select constructors used by basic_string's concatenation operators (operator+)