diff options
author | Marshall Clow <mclow.lists@gmail.com> | 2019-03-28 17:30:23 +0000 |
---|---|---|
committer | Marshall Clow <mclow.lists@gmail.com> | 2019-03-28 17:30:23 +0000 |
commit | 1931c4306a38cb60ea6fbfefd238302909e57d42 (patch) | |
tree | 46b6348734f9e7c5709f2c2f03f2263a71a2e56e /libcxx/include/regex | |
parent | 1dd1b5d5f254ef25dd184d71cb60db92a750d96b (diff) | |
download | bcm5719-llvm-1931c4306a38cb60ea6fbfefd238302909e57d42.tar.gz bcm5719-llvm-1931c4306a38cb60ea6fbfefd238302909e57d42.zip |
Fix PR#35967: '<regex> syntax_option_type is not a proper bitmask' Sadly, this is an ABI break, so it's only available if you define either '_LIBCPP_ABI_VERSION > 2' or '_LIBCPP_ABI_UNSTABLE' or '_LIBCPP_ABI_REGEX_CONSTANTS_NONZERO' and rebuild your dylib.
llvm-svn: 357190
Diffstat (limited to 'libcxx/include/regex')
-rw-r--r-- | libcxx/include/regex | 56 |
1 files changed, 44 insertions, 12 deletions
diff --git a/libcxx/include/regex b/libcxx/include/regex index c381b5116af..b9aa9d63395 100644 --- a/libcxx/include/regex +++ b/libcxx/include/regex @@ -793,7 +793,11 @@ enum syntax_option_type nosubs = 1 << 1, optimize = 1 << 2, collate = 1 << 3, +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + ECMAScript = 1 << 9, +#else ECMAScript = 0, +#endif basic = 1 << 4, extended = 1 << 5, awk = 1 << 6, @@ -801,6 +805,16 @@ enum syntax_option_type egrep = 1 << 8 }; +inline _LIBCPP_CONSTEXPR +syntax_option_type __get_grammar(syntax_option_type __g) +{ +#ifdef _LIBCPP_ABI_REGEX_CONSTANTS_NONZERO + return static_cast<syntax_option_type>(__g & 0x3F0); +#else + return static_cast<syntax_option_type>(__g & 0x1F0); +#endif +} + inline _LIBCPP_INLINE_VISIBILITY _LIBCPP_CONSTEXPR syntax_option_type @@ -2526,19 +2540,27 @@ public: // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY basic_regex() - : __flags_(), __marked_count_(0), __loop_count_(0), __open_count_(0), + : __flags_(regex_constants::ECMAScript), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) {} _LIBCPP_INLINE_VISIBILITY explicit basic_regex(const value_type* __p, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p, __p + __traits_.length(__p));} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __traits_.length(__p)); + } + _LIBCPP_INLINE_VISIBILITY basic_regex(const value_type* __p, size_t __len, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p, __p + __len);} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p, __p + __len); + } + // basic_regex(const basic_regex&) = default; // basic_regex(basic_regex&&) = default; template <class _ST, class _SA> @@ -2547,21 +2569,31 @@ public: flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__p.begin(), __p.end());} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__p.begin(), __p.end()); + } + template <class _ForwardIterator> _LIBCPP_INLINE_VISIBILITY basic_regex(_ForwardIterator __first, _ForwardIterator __last, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__first, __last);} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__first, __last); + } #ifndef _LIBCPP_CXX03_LANG _LIBCPP_INLINE_VISIBILITY basic_regex(initializer_list<value_type> __il, flag_type __f = regex_constants::ECMAScript) : __flags_(__f), __marked_count_(0), __loop_count_(0), __open_count_(0), __end_(0) - {__parse(__il.begin(), __il.end());} + { + if (__get_grammar(__flags_) == 0) __flags_ |= regex_constants::ECMAScript; + __parse(__il.begin(), __il.end()); + } #endif // _LIBCPP_CXX03_LANG // ~basic_regex() = default; @@ -3043,7 +3075,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first, __h.release(); __end_ = __start_.get(); } - switch (__flags_ & 0x1F0) + switch (__get_grammar(__flags_)) { case ECMAScript: __first = __parse_ecma_exp(__first, __last); @@ -3512,7 +3544,7 @@ basic_regex<_CharT, _Traits>::__parse_QUOTED_CHAR_ERE(_ForwardIterator __first, __first = ++__temp; break; default: - if ((__flags_ & 0x1F0) == awk) + if (__get_grammar(__flags_) == awk) __first = __parse_awk_escape(++__first, __last); break; } @@ -3596,7 +3628,7 @@ basic_regex<_CharT, _Traits>::__parse_ERE_dupl_symbol(_ForwardIterator __first, { if (__first != __last) { - unsigned __grammar = __flags_ & 0x1F0; + unsigned __grammar = __get_grammar(__flags_); switch (*__first) { case '*': @@ -3717,7 +3749,7 @@ basic_regex<_CharT, _Traits>::__parse_bracket_expression(_ForwardIterator __firs // __ml owned by *this if (__first == __last) __throw_regex_error<regex_constants::error_brack>(); - if ((__flags_ & 0x1F0) != ECMAScript && *__first == ']') + if (__get_grammar(__flags_) != ECMAScript && *__first == ']') { __ml->__add_char(']'); ++__first; @@ -3778,7 +3810,7 @@ basic_regex<_CharT, _Traits>::__parse_expression_term(_ForwardIterator __first, else if (*__temp == '.') __first = __parse_collating_symbol(++__temp, __last, __start_range); } - unsigned __grammar = __flags_ & 0x1F0; + unsigned __grammar = __get_grammar(__flags_); if (__start_range.empty()) { if ((__grammar == ECMAScript || __grammar == awk) && *__first == '\\') @@ -5848,7 +5880,7 @@ basic_regex<_CharT, _Traits>::__match_at_start( match_results<const _CharT*, _Allocator>& __m, regex_constants::match_flag_type __flags, bool __at_first) const { - if ((__flags_ & 0x1F0) == ECMAScript) + if (__get_grammar(__flags_) == ECMAScript) return __match_at_start_ecma(__first, __last, __m, __flags, __at_first); if (mark_count() == 0) return __match_at_start_posix_nosubs(__first, __last, __m, __flags, __at_first); |