From 00e802c671917473c1a9ecb6034a4a6ea78ae3a3 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sat, 2 Dec 2017 18:24:00 +0200 Subject: [PATCH 01/24] Add `quick` test target (for CI) --- test/Jamfile.v2 | 3 ++- test/quick.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 test/quick.cpp diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index afde5fe7..f485058c 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -194,4 +194,5 @@ compile test_consolidated.cpp ; build-project ../example ; - +# `quick` target (for CI) +run quick.cpp ../build//boost_regex ; diff --git a/test/quick.cpp b/test/quick.cpp new file mode 100644 index 00000000..edc361a9 --- /dev/null +++ b/test/quick.cpp @@ -0,0 +1,55 @@ + +// Copyright 1998-2002 John Maddock +// Copyright 2017 Peter Dimov +// +// Distributed under the Boost Software License, Version 1.0. +// +// See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt + +// See library home page at http://www.boost.org/libs/regex + +#include +#include +#include + +bool validate_card_format(const std::string& s) +{ + static const boost::regex e("(\\d{4}[- ]){3}\\d{4}"); + return boost::regex_match(s, e); +} + +const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); +const std::string machine_format("\\1\\2\\3\\4"); +const std::string human_format("\\1-\\2-\\3-\\4"); + +std::string machine_readable_card_number(const std::string& s) +{ + return boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed); +} + +std::string human_readable_card_number(const std::string& s) +{ + return boost::regex_replace(s, e, human_format, boost::match_default | boost::format_sed); +} + +int main() +{ + std::string s[ 4 ] = { "0000111122223333", "0000 1111 2222 3333", "0000-1111-2222-3333", "000-1111-2222-3333" }; + + BOOST_TEST( !validate_card_format( s[0] ) ); + BOOST_TEST_EQ( machine_readable_card_number( s[0] ), s[0] ); + BOOST_TEST_EQ( human_readable_card_number( s[0] ), s[2] ); + + BOOST_TEST( validate_card_format( s[1] ) ); + BOOST_TEST_EQ( machine_readable_card_number( s[1] ), s[0] ); + BOOST_TEST_EQ( human_readable_card_number( s[1] ), s[2] ); + + BOOST_TEST( validate_card_format( s[2] ) ); + BOOST_TEST_EQ( machine_readable_card_number( s[2] ), s[0] ); + BOOST_TEST_EQ( human_readable_card_number( s[2] ), s[2] ); + + BOOST_TEST( !validate_card_format( s[3] ) ); + + return boost::report_errors(); +} From 47be67134a14ab0f6c1a633203f2e081564d7fdb Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 3 Dec 2017 00:36:11 +0200 Subject: [PATCH 02/24] Fix -Wshadow warnings in quick.cpp --- test/quick.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/quick.cpp b/test/quick.cpp index edc361a9..0598823d 100644 --- a/test/quick.cpp +++ b/test/quick.cpp @@ -19,18 +19,18 @@ bool validate_card_format(const std::string& s) return boost::regex_match(s, e); } -const boost::regex e("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); +const boost::regex card_rx("\\A(\\d{3,4})[- ]?(\\d{4})[- ]?(\\d{4})[- ]?(\\d{4})\\z"); const std::string machine_format("\\1\\2\\3\\4"); const std::string human_format("\\1-\\2-\\3-\\4"); std::string machine_readable_card_number(const std::string& s) { - return boost::regex_replace(s, e, machine_format, boost::match_default | boost::format_sed); + return boost::regex_replace(s, card_rx, machine_format, boost::match_default | boost::format_sed); } std::string human_readable_card_number(const std::string& s) { - return boost::regex_replace(s, e, human_format, boost::match_default | boost::format_sed); + return boost::regex_replace(s, card_rx, human_format, boost::match_default | boost::format_sed); } int main() From b41d9dc3233e5756b25570f6ffc85dd5756387ab Mon Sep 17 00:00:00 2001 From: Forrest Reiling Date: Fri, 8 Dec 2017 17:07:51 -0800 Subject: [PATCH 03/24] Move BOOST_REGEX_DETAIL_NS::RegExData::type_pf cases out of BOOST_REGEX_NO_FILEITER to avoid compiler warnings about missing cases in case statement --- src/cregex.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cregex.cpp b/src/cregex.cpp index 01efc3f3..a1ae3b08 100644 --- a/src/cregex.cpp +++ b/src/cregex.cpp @@ -491,8 +491,8 @@ std::size_t RegEx::Position(int i)const { case BOOST_REGEX_DETAIL_NS::RegExData::type_pc: return pdata->m[i].matched ? pdata->m[i].first - pdata->pbase : RegEx::npos; -#ifndef BOOST_REGEX_NO_FILEITER case BOOST_REGEX_DETAIL_NS::RegExData::type_pf: +#ifndef BOOST_REGEX_NO_FILEITER return pdata->fm[i].matched ? pdata->fm[i].first - pdata->fbase : RegEx::npos; #endif case BOOST_REGEX_DETAIL_NS::RegExData::type_copy: @@ -518,8 +518,8 @@ std::size_t RegEx::Length(int i)const { case BOOST_REGEX_DETAIL_NS::RegExData::type_pc: return pdata->m[i].matched ? pdata->m[i].second - pdata->m[i].first : RegEx::npos; -#ifndef BOOST_REGEX_NO_FILEITER case BOOST_REGEX_DETAIL_NS::RegExData::type_pf: +#ifndef BOOST_REGEX_NO_FILEITER return pdata->fm[i].matched ? pdata->fm[i].second - pdata->fm[i].first : RegEx::npos; #endif case BOOST_REGEX_DETAIL_NS::RegExData::type_copy: @@ -539,10 +539,10 @@ bool RegEx::Matched(int i)const { case BOOST_REGEX_DETAIL_NS::RegExData::type_pc: return pdata->m[i].matched; -#ifndef BOOST_REGEX_NO_FILEITER case BOOST_REGEX_DETAIL_NS::RegExData::type_pf: +#ifndef BOOST_REGEX_NO_FILEITER return pdata->fm[i].matched; -#endif +#endif case BOOST_REGEX_DETAIL_NS::RegExData::type_copy: { std::map >::iterator pos = pdata->strings.find(i); From a3f1cf9dfc447f665dbb749d3ad9312e331d8059 Mon Sep 17 00:00:00 2001 From: rummt Date: Tue, 12 Dec 2017 11:07:59 +0000 Subject: [PATCH 04/24] typo in error message 'openening' should be 'opening' --- include/boost/regex/v4/basic_regex_parser.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/regex/v4/basic_regex_parser.hpp b/include/boost/regex/v4/basic_regex_parser.hpp index 7c2852fa..dc528a39 100644 --- a/include/boost/regex/v4/basic_regex_parser.hpp +++ b/include/boost/regex/v4/basic_regex_parser.hpp @@ -183,7 +183,7 @@ void basic_regex_parser::parse(const charT* p1, const charT* p2, // have had an unexpected ')' : if(!result) { - fail(regex_constants::error_paren, ::boost::BOOST_REGEX_DETAIL_NS::distance(m_base, m_position), "Found a closing ) with no corresponding openening parenthesis."); + fail(regex_constants::error_paren, ::boost::BOOST_REGEX_DETAIL_NS::distance(m_base, m_position), "Found a closing ) with no corresponding opening parenthesis."); return; } // if an error has been set then give up now: From e62d8b53324a3faf147d875902c4c4d84555e6ac Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 16 Dec 2017 09:26:33 +0000 Subject: [PATCH 05/24] Regex.C++17: Fix iterator usage. --- example/timer/regex_timer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/timer/regex_timer.cpp b/example/timer/regex_timer.cpp index a6924237..ad47dcee 100644 --- a/example/timer/regex_timer.cpp +++ b/example/timer/regex_timer.cpp @@ -72,11 +72,13 @@ class string_out_iterator #endif // ndef BOOST_NO_STD_ITERATOR { #ifdef BOOST_NO_STD_ITERATOR +public: typedef std::output_iterator_tag iterator_category; typedef void value_type; typedef void difference_type; typedef void pointer; typedef void reference; +private: #endif // BOOST_NO_STD_ITERATOR S* out; From e6ce5523c668f912c1cff6503da5a55302aa7880 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Mon, 18 Dec 2017 17:56:53 +0100 Subject: [PATCH 06/24] replace members of std::allocate which are deprecated in c++17 by their cousins from std::allocator_traits. Signed-off-by: Daniela Engert --- include/boost/regex/v4/match_results.hpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/boost/regex/v4/match_results.hpp b/include/boost/regex/v4/match_results.hpp index c8233bdd..92e488d2 100644 --- a/include/boost/regex/v4/match_results.hpp +++ b/include/boost/regex/v4/match_results.hpp @@ -56,7 +56,9 @@ private: #endif public: typedef sub_match value_type; -#if !defined(BOOST_NO_STD_ALLOCATOR) && !(defined(BOOST_MSVC) && defined(_STLPORT_VERSION)) +#ifndef BOOST_NO_CXX11_ALLOCATOR + typedef typename std::allocator_traits::value_type const & const_reference; +#elif !defined(BOOST_NO_STD_ALLOCATOR) && !(defined(BOOST_MSVC) && defined(_STLPORT_VERSION)) typedef typename Allocator::const_reference const_reference; #else typedef const value_type& const_reference; @@ -66,7 +68,11 @@ public: typedef const_iterator iterator; typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits< BidiIterator>::difference_type difference_type; +#ifdef BOOST_NO_CXX11_ALLOCATOR typedef typename Allocator::size_type size_type; +#else + typedef typename std::allocator_traits::size_type size_type; +#endif typedef Allocator allocator_type; typedef typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits< BidiIterator>::value_type char_type; From cc5a4e85ae0f0e21c9c1aa7c17a1d19dc59b18c8 Mon Sep 17 00:00:00 2001 From: Daniela Engert Date: Mon, 18 Dec 2017 19:15:52 +0100 Subject: [PATCH 07/24] Inheriting std::iterator is deprecated in c++17. Therefore replace the inheritance by lifting std::iterator's members into the derived class. Fortunately, this is already done in Boost.Regex so that dropping the inheritance is a no-brainer. Signed-off-by: Daniela Engert --- example/timer/regex_timer.cpp | 6 ------ include/boost/regex/v4/fileiter.hpp | 3 --- include/boost/regex/v4/regex_format.hpp | 5 ----- include/boost/regex/v4/regex_iterator.hpp | 8 -------- include/boost/regex/v4/regex_token_iterator.hpp | 8 -------- include/boost/regex/v4/u32regex_iterator.hpp | 8 -------- include/boost/regex/v4/u32regex_token_iterator.hpp | 8 -------- test/regress/test_icu.cpp | 8 ++++---- 8 files changed, 4 insertions(+), 50 deletions(-) diff --git a/example/timer/regex_timer.cpp b/example/timer/regex_timer.cpp index ad47dcee..48f41a9b 100644 --- a/example/timer/regex_timer.cpp +++ b/example/timer/regex_timer.cpp @@ -67,11 +67,7 @@ ostream& operator << (ostream& os, const std::wstring& s) template class string_out_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator -#endif // ndef BOOST_NO_STD_ITERATOR { -#ifdef BOOST_NO_STD_ITERATOR public: typedef std::output_iterator_tag iterator_category; typedef void value_type; @@ -79,8 +75,6 @@ public: typedef void pointer; typedef void reference; private: -#endif // BOOST_NO_STD_ITERATOR - S* out; public: string_out_iterator(S& s) : out(&s) {} diff --git a/include/boost/regex/v4/fileiter.hpp b/include/boost/regex/v4/fileiter.hpp index 256a7e46..7c865c63 100644 --- a/include/boost/regex/v4/fileiter.hpp +++ b/include/boost/regex/v4/fileiter.hpp @@ -195,9 +195,6 @@ public: }; class BOOST_REGEX_DECL mapfile_iterator -#if !defined(BOOST_NO_STD_ITERATOR) || defined(BOOST_MSVC_STD_ITERATOR) -: public std::iterator -#endif { typedef mapfile::pointer internal_pointer; internal_pointer* node; diff --git a/include/boost/regex/v4/regex_format.hpp b/include/boost/regex/v4/regex_format.hpp index f0a0a11e..b65ffcc9 100644 --- a/include/boost/regex/v4/regex_format.hpp +++ b/include/boost/regex/v4/regex_format.hpp @@ -800,9 +800,6 @@ void basic_regex_formatter::put(co template class string_out_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator -#endif { S* out; public: @@ -816,13 +813,11 @@ public: return *this; } -#ifdef BOOST_NO_STD_ITERATOR typedef std::ptrdiff_t difference_type; typedef typename S::value_type value_type; typedef value_type* pointer; typedef value_type& reference; typedef std::output_iterator_tag iterator_category; -#endif }; template diff --git a/include/boost/regex/v4/regex_iterator.hpp b/include/boost/regex/v4/regex_iterator.hpp index 0d10a1b9..380a9a71 100644 --- a/include/boost/regex/v4/regex_iterator.hpp +++ b/include/boost/regex/v4/regex_iterator.hpp @@ -85,14 +85,6 @@ template ::value_type, class traits = regex_traits > class regex_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator< - std::forward_iterator_tag, - match_results, - typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits::difference_type, - const match_results*, - const match_results& > -#endif { private: typedef regex_iterator_implementation impl; diff --git a/include/boost/regex/v4/regex_token_iterator.hpp b/include/boost/regex/v4/regex_token_iterator.hpp index 1d75604b..fde51d74 100644 --- a/include/boost/regex/v4/regex_token_iterator.hpp +++ b/include/boost/regex/v4/regex_token_iterator.hpp @@ -167,14 +167,6 @@ template ::value_type, class traits = regex_traits > class regex_token_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator< - std::forward_iterator_tag, - sub_match, - typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits::difference_type, - const sub_match*, - const sub_match& > -#endif { private: typedef regex_token_iterator_implementation impl; diff --git a/include/boost/regex/v4/u32regex_iterator.hpp b/include/boost/regex/v4/u32regex_iterator.hpp index 701ef3d8..df697521 100644 --- a/include/boost/regex/v4/u32regex_iterator.hpp +++ b/include/boost/regex/v4/u32regex_iterator.hpp @@ -72,14 +72,6 @@ private: template class u32regex_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator< - std::forward_iterator_tag, - match_results, - typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits::difference_type, - const match_results*, - const match_results& > -#endif { private: typedef u32regex_iterator_implementation impl; diff --git a/include/boost/regex/v4/u32regex_token_iterator.hpp b/include/boost/regex/v4/u32regex_token_iterator.hpp index 9eabbe48..a056102c 100644 --- a/include/boost/regex/v4/u32regex_token_iterator.hpp +++ b/include/boost/regex/v4/u32regex_token_iterator.hpp @@ -155,14 +155,6 @@ private: template class u32regex_token_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator< - std::forward_iterator_tag, - sub_match, - typename BOOST_REGEX_DETAIL_NS::regex_iterator_traits::difference_type, - const sub_match*, - const sub_match& > -#endif { private: typedef u32regex_token_iterator_implementation impl; diff --git a/test/regress/test_icu.cpp b/test/regress/test_icu.cpp index 67044f0e..1ef9fa96 100644 --- a/test/regress/test_icu.cpp +++ b/test/regress/test_icu.cpp @@ -33,16 +33,16 @@ namespace unnecessary_fix{ // template class back_insert_iterator -#ifndef BOOST_NO_STD_ITERATOR - : public std::iterator -#endif { private: Seq* container; public: typedef const typename Seq::value_type value_type; typedef Seq container_type; - typedef std::output_iterator_tag iterator_category; + typedef void difference_type; + typedef void pointer; + typedef void reference; + typedef std::output_iterator_tag iterator_category; explicit back_insert_iterator(Seq& x) : container(&x) {} back_insert_iterator& operator=(const value_type& val) From 59d501b07b55b1f39d977a95c3201157051789a8 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 23 Dec 2017 19:18:08 +0000 Subject: [PATCH 08/24] Regex: fix integer shift warning/error in icu.cpp --- src/icu.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/icu.cpp b/src/icu.cpp index be6e5a1c..d101d65d 100644 --- a/src/icu.cpp +++ b/src/icu.cpp @@ -481,7 +481,7 @@ icu_regex_traits::string_type icu_regex_traits::lookup_collatename(const char_ty bool icu_regex_traits::isctype(char_type c, char_class_type f) const { // check for standard catagories first: - char_class_type m = char_class_type(1u << u_charType(c)); + char_class_type m = char_class_type(1uLL << u_charType(c)); if((m & f) != 0) return true; // now check for special cases: From 799b09dc26b39c0231264000d2287eb2dc2f39b2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 24 Dec 2017 01:49:32 +0200 Subject: [PATCH 09/24] Define BOOST_REGEX_UCHAR_IS_WCHAR_T, use it to disable overloads --- include/boost/regex/icu.hpp | 39 ++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/include/boost/regex/icu.hpp b/include/boost/regex/icu.hpp index cdae1c8b..1bf71cb4 100644 --- a/include/boost/regex/icu.hpp +++ b/include/boost/regex/icu.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #ifdef BOOST_MSVC @@ -334,6 +335,34 @@ inline u32regex do_make_u32regex(InputIterator i, #endif } +// BOOST_REGEX_UCHAR_IS_WCHAR_T +// +// Source inspection of unicode/umachine.h in ICU version 59 indicates that: +// +// On version 59, UChar is always char16_t in C++ mode (and uint16_t in C mode) +// +// On earlier versions, the logic is +// +// #if U_SIZEOF_WCHAR_T==2 +// typedef wchar_t OldUChar; +// #elif defined(__CHAR16_TYPE__) +// typedef __CHAR16_TYPE__ OldUChar; +// #else +// typedef uint16_t OldUChar; +// #endif +// +// That is, UChar is wchar_t only on versions below 59, when U_SIZEOF_WCHAR_T==2 +// +// Hence, + +#define BOOST_REGEX_UCHAR_IS_WCHAR_T (U_ICU_VERSION_MAJOR_NUM < 59 && U_SIZEOF_WCHAR_T == 2) + +#if BOOST_REGEX_UCHAR_IS_WCHAR_T + BOOST_STATIC_ASSERT((boost::is_same::value)); +#else + BOOST_STATIC_ASSERT(!(boost::is_same::value)); +#endif + // // Construction from an iterator pair: // @@ -364,7 +393,7 @@ inline u32regex make_u32regex(const wchar_t* p, boost::regex_constants::syntax_o return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + std::wcslen(p), opt, static_cast const*>(0)); } #endif -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) +#if !BOOST_REGEX_UCHAR_IS_WCHAR_T inline u32regex make_u32regex(const UChar* p, boost::regex_constants::syntax_option_type opt = boost::regex_constants::perl) { return BOOST_REGEX_DETAIL_NS::do_make_u32regex(p, p + u_strlen(p), opt, static_cast const*>(0)); @@ -481,7 +510,7 @@ inline bool u32regex_match(const UChar* p, { return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast const*>(0)); } -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX) +#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) inline bool u32regex_match(const wchar_t* p, match_results& m, const u32regex& e, @@ -545,7 +574,7 @@ inline bool u32regex_match(const UChar* p, match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_match(p, p+u_strlen(p), m, e, flags, static_cast const*>(0)); } -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX) +#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) inline bool u32regex_match(const wchar_t* p, const u32regex& e, match_flag_type flags = match_default) @@ -666,7 +695,7 @@ inline bool u32regex_search(const UChar* p, { return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast const*>(0)); } -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX) +#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) inline bool u32regex_search(const wchar_t* p, match_results& m, const u32regex& e, @@ -727,7 +756,7 @@ inline bool u32regex_search(const UChar* p, match_results m; return BOOST_REGEX_DETAIL_NS::do_regex_search(p, p+u_strlen(p), m, e, flags, p, static_cast const*>(0)); } -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) && !defined(BOOST_NO_WREGEX) +#if !BOOST_REGEX_UCHAR_IS_WCHAR_T && !defined(BOOST_NO_WREGEX) inline bool u32regex_search(const wchar_t* p, const u32regex& e, match_flag_type flags = match_default) From 3043906da2d825035d701cbc0685434e65618b1f Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 24 Dec 2017 18:39:54 +0000 Subject: [PATCH 10/24] Regex.ICU: use BOOST_REGEX_UCHAR_IS_WCHAR_T in a few other places, and improve concept checks. --- include/boost/regex/v4/u32regex_iterator.hpp | 2 +- .../regex/v4/u32regex_token_iterator.hpp | 4 +- test/concepts/icu_concept_check.cpp | 85 +++++++++++++++++++ 3 files changed, 88 insertions(+), 3 deletions(-) diff --git a/include/boost/regex/v4/u32regex_iterator.hpp b/include/boost/regex/v4/u32regex_iterator.hpp index df697521..f8763a8d 100644 --- a/include/boost/regex/v4/u32regex_iterator.hpp +++ b/include/boost/regex/v4/u32regex_iterator.hpp @@ -158,7 +158,7 @@ inline u32regex_iterator make_u32regex_iterator(const wchar_t* p return u32regex_iterator(p, p+std::wcslen(p), e, m); } #endif -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) +#if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T) inline u32regex_iterator make_u32regex_iterator(const UChar* p, const u32regex& e, regex_constants::match_flag_type m = regex_constants::match_default) { return u32regex_iterator(p, p+u_strlen(p), e, m); diff --git a/include/boost/regex/v4/u32regex_token_iterator.hpp b/include/boost/regex/v4/u32regex_token_iterator.hpp index a056102c..952f7c41 100644 --- a/include/boost/regex/v4/u32regex_token_iterator.hpp +++ b/include/boost/regex/v4/u32regex_token_iterator.hpp @@ -267,7 +267,7 @@ inline u32regex_token_iterator make_u32regex_token_iterator(cons return u32regex_token_iterator(p, p+std::wcslen(p), e, submatch, m); } #endif -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) +#if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T) inline u32regex_token_iterator make_u32regex_token_iterator(const UChar* p, const u32regex& e, int submatch = 0, regex_constants::match_flag_type m = regex_constants::match_default) { return u32regex_token_iterator(p, p+u_strlen(p), e, submatch, m); @@ -297,7 +297,7 @@ inline u32regex_token_iterator make_u32regex_token_iterator(cons return u32regex_token_iterator(p, p+std::wcslen(p), e, submatch, m); } #endif -#if !defined(U_WCHAR_IS_UTF16) && (U_SIZEOF_WCHAR_T != 2) +#if !defined(BOOST_REGEX_UCHAR_IS_WCHAR_T) template inline u32regex_token_iterator make_u32regex_token_iterator(const UChar* p, const u32regex& e, const int (&submatch)[N], regex_constants::match_flag_type m = regex_constants::match_default) { diff --git a/test/concepts/icu_concept_check.cpp b/test/concepts/icu_concept_check.cpp index 3c1363eb..a55bb387 100644 --- a/test/concepts/icu_concept_check.cpp +++ b/test/concepts/icu_concept_check.cpp @@ -33,7 +33,34 @@ #include #endif +template +void check_token_iterator(I i) +{ + typedef typename I::value_type value_type; + typedef typename value_type::value_type char_type; + typedef std::basic_string string_type; + I j; + + std::vector v; + + while (i != j) + { + v.push_back(i->str()); + ++i; + } + +} + +template +void check_iterator(I i) +{ + typedef typename I::value_type value_type; + + std::vector v(i, I()); + (void)v; + +} int main() { // VC6 and VC7 can't cope with the iterator architypes, @@ -150,6 +177,64 @@ int main() s1 = boost::u32regex_replace(s1, e1, s1); s2 = boost::u32regex_replace(s2, e1, s2); + std::vector subs1; + int subs2[2] = { 1, 2 }; + + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, 0)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1)); + + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs2)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs2)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs2)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs2)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs2)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs2)); + + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const char*)(pb), e1, subs1)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const UChar*)(pb), e1, subs1)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator((const wchar_t*)(pb), e1, subs1)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s1, e1, subs1)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(s2, e1, subs1)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1, boost::regex_constants::match_default)); + check_token_iterator(boost::make_u32regex_token_iterator(us, e1, subs1)); + + check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1, boost::regex_constants::match_default)); + check_iterator(boost::make_u32regex_iterator((const char*)(pb), e1)); + check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1, boost::regex_constants::match_default)); + check_iterator(boost::make_u32regex_iterator((const UChar*)(pb), e1)); + check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1, boost::regex_constants::match_default)); + check_iterator(boost::make_u32regex_iterator((const wchar_t*)(pb), e1)); + check_iterator(boost::make_u32regex_iterator(s1, e1, boost::regex_constants::match_default)); + check_iterator(boost::make_u32regex_iterator(s2, e1)); + check_iterator(boost::make_u32regex_iterator(us, e1)); + #endif return 0; } From b13fb44ac594400b5af78dbc2ec0fbbb742e35b0 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 3 Jan 2018 18:32:45 +0000 Subject: [PATCH 11/24] Regex.Defuzzing: Fix for https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4659&q=jz.maddock&colspec=ID%20Type%20Component%20Status%20Proj%20Reported%20Owner%20Summary --- include/boost/regex/v4/perl_matcher_non_recursive.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/regex/v4/perl_matcher_non_recursive.hpp b/include/boost/regex/v4/perl_matcher_non_recursive.hpp index 3d89749d..79d6d76c 100644 --- a/include/boost/regex/v4/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_non_recursive.hpp @@ -1797,7 +1797,7 @@ bool perl_matcher::unwind_recursion_pop(bool r) // Backtracking out of a recursion, we must pop state off the recursion // stack unconditionally to ensure matched pushes and pops: saved_state* pmp = static_cast(m_backup_state); - if (!r) + if (!r && !recursion_stack.empty()) { *m_presult = recursion_stack.back().results; position = recursion_stack.back().location_of_start; From fa8b79bca9e0b6d30e90a54c8b62a66b8bedf838 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Thu, 4 Jan 2018 18:51:21 +0000 Subject: [PATCH 12/24] Regex.Defuzz, fix for https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4615 --- include/boost/regex/v4/perl_matcher_non_recursive.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/include/boost/regex/v4/perl_matcher_non_recursive.hpp b/include/boost/regex/v4/perl_matcher_non_recursive.hpp index 79d6d76c..1cda64d9 100644 --- a/include/boost/regex/v4/perl_matcher_non_recursive.hpp +++ b/include/boost/regex/v4/perl_matcher_non_recursive.hpp @@ -1834,6 +1834,7 @@ bool perl_matcher::unwind_commit(bool b) // If we stop because we just unwound an assertion, put the // commit state back on the stack again: // + m_unwound_lookahead = false; saved_state* pmp = m_backup_state; --pmp; if(pmp < m_stack_base) From e39a99c6f5f53de2510a7ee609cd4fdc1bf6cf10 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Fri, 5 Jan 2018 12:59:30 +0000 Subject: [PATCH 13/24] Update CI dependency list --- .travis.yml | 1 + appveyor.yml | 1 + 2 files changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index df49941a..ae6c5e50 100644 --- a/.travis.yml +++ b/.travis.yml @@ -213,6 +213,7 @@ install: - git submodule update --init tools/build - git submodule update --init libs/config - git submodule update --init libs/core + - git submodule update --init libs/container_hash - git submodule update --init libs/detail - git submodule update --init libs/smart_ptr - git submodule update --init libs/predef diff --git a/appveyor.yml b/appveyor.yml index 433b30e9..b131adcd 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -47,6 +47,7 @@ install: - git submodule update --init tools/build - git submodule update --init libs/config - git submodule update --init libs/core + - git submodule update --init libs/container_hash - git submodule update --init libs/detail - git submodule update --init libs/smart_ptr - git submodule update --init libs/predef From 80a2a12b7aedbcd509dce979bb02341170d1ad78 Mon Sep 17 00:00:00 2001 From: Peter Klotz Date: Sun, 11 Feb 2018 20:35:50 +0100 Subject: [PATCH 14/24] Fixed typo in exception text --- include/boost/regex/v4/match_results.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/boost/regex/v4/match_results.hpp b/include/boost/regex/v4/match_results.hpp index 92e488d2..6af46952 100644 --- a/include/boost/regex/v4/match_results.hpp +++ b/include/boost/regex/v4/match_results.hpp @@ -569,7 +569,7 @@ private: // static void raise_logic_error() { - std::logic_error e("Attempt to access an uninitialzed boost::match_results<> class."); + std::logic_error e("Attempt to access an uninitialized boost::match_results<> class."); boost::throw_exception(e); } From 35fbb2e5e2a97d0eeed35a7f6c2703beedba4057 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Tue, 17 Jul 2018 19:36:03 +0100 Subject: [PATCH 15/24] Disable some std::locale tests with VC15.7 as they (incorrectly) assert in the C runtime. --- test/regress/test_locale.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/regress/test_locale.cpp b/test/regress/test_locale.cpp index 692d83e6..54cd56ab 100644 --- a/test/regress/test_locale.cpp +++ b/test/regress/test_locale.cpp @@ -49,7 +49,9 @@ test_locale::test_locale(const char* c_name, boost::uint32_t lcid) #else s_c_locale = no_test; #endif -#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS) + // Disabled for VC15.7 (and later?) as the C runtime asserts if you pass an invalid + // locale name to std::locale, rather than throwing the expected exception. +#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS) && !BOOST_WORKAROUND(BOOST_MSVC, > 1913) // back up the C++ locale and create the new one: m_old_cpp_locale = s_cpp_locale_inst; m_old_cpp_state = s_cpp_locale; From ac49efa23fc7c1d0e426b228d2206b57ebc95ce5 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 18 Jul 2018 18:30:14 +0100 Subject: [PATCH 16/24] Apply changes from https://github.com/boostorg/regex/pull/16 --- include/boost/regex/v4/regex_workaround.hpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/include/boost/regex/v4/regex_workaround.hpp b/include/boost/regex/v4/regex_workaround.hpp index f245f90d..35eafc25 100644 --- a/include/boost/regex/v4/regex_workaround.hpp +++ b/include/boost/regex/v4/regex_workaround.hpp @@ -198,9 +198,10 @@ namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ const char *strSource ) { - if(std::strlen(strSource)+1 > sizeInBytes) + std::size_t lenSourceWithNull = std::strlen(strSource) + 1; + if (lenSourceWithNull > sizeInBytes) return 1; - std::strcpy(strDestination, strSource); + std::memcpy(strDestination, strSource, lenSourceWithNull); return 0; } inline std::size_t strcat_s( @@ -209,9 +210,11 @@ namespace boost{ namespace BOOST_REGEX_DETAIL_NS{ const char *strSource ) { - if(std::strlen(strSource) + std::strlen(strDestination) + 1 > sizeInBytes) + std::size_t lenSourceWithNull = std::strlen(strSource) + 1; + std::size_t lenDestination = std::strlen(strDestination); + if (lenSourceWithNull + lenDestination > sizeInBytes) return 1; - std::strcat(strDestination, strSource); + std::memcpy(strDestination + lenDestination, strSource, lenSourceWithNull); return 0; } From 867cc5f0fcc4d52729901b759058974798ff5793 Mon Sep 17 00:00:00 2001 From: John Maddock Date: Wed, 18 Jul 2018 18:57:07 +0100 Subject: [PATCH 17/24] Stop using BOOST_WORKAROUND in a header which may be included in C code. --- include/boost/regex/v4/match_flags.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/boost/regex/v4/match_flags.hpp b/include/boost/regex/v4/match_flags.hpp index 1938b27a..aa8fd532 100644 --- a/include/boost/regex/v4/match_flags.hpp +++ b/include/boost/regex/v4/match_flags.hpp @@ -22,7 +22,6 @@ #ifdef __cplusplus # include #endif -#include #ifdef __cplusplus namespace boost{ @@ -83,7 +82,7 @@ typedef enum _match_flags } match_flags; -#if defined(__BORLANDC__) || BOOST_WORKAROUND(BOOST_MSVC, <= 1310) +#if defined(__BORLANDC__) || (defined(_MSC_VER) && (_MSC_VER <= 1310)) typedef unsigned long match_flag_type; #else typedef match_flags match_flag_type; From 39f1cc0238f22fc3bd6a1b9ded1a74c62910bf74 Mon Sep 17 00:00:00 2001 From: "James E. King III" Date: Tue, 17 Jul 2018 14:00:08 +0000 Subject: [PATCH 18/24] resolve some warnings --- include/boost/regex/concepts.hpp | 5 +++-- src/fileiter.cpp | 2 +- src/icu.cpp | 2 +- test/c_compiler_checks/posix_api_check.c | 4 ++-- test/c_compiler_checks/wide_posix_api_check.c | 4 ++-- test/captures/captures_test.cpp | 4 ++-- test/test_macros.hpp | 4 ++-- test/unicode/unicode_iterator_test.cpp | 8 ++++++++ 8 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/boost/regex/concepts.hpp b/include/boost/regex/concepts.hpp index 8cd5d995..276e63f7 100644 --- a/include/boost/regex/concepts.hpp +++ b/include/boost/regex/concepts.hpp @@ -437,7 +437,8 @@ struct BaseRegexConcept ignore_unused_variable_warning(bi); sub_diff_type diff = m_sub.length(); ignore_unused_variable_warning(diff); - // match_results tests: + // match_results tests - some typedefs are not used, however these + // guarante that they exist (some compilers may warn on non-usage) typedef typename match_results_type::value_type mr_value_type; typedef typename match_results_type::const_reference mr_const_reference; typedef typename match_results_type::reference mr_reference; @@ -483,7 +484,7 @@ struct BaseRegexConcept mrci = m_cresults.end(); ignore_unused_variable_warning(mrci); - mr_allocator_type at2 = m_cresults.get_allocator(); + (void) m_cresults.get_allocator(); m_results.swap(m_results); global_regex_namespace::swap(m_results, m_results); diff --git a/src/fileiter.cpp b/src/fileiter.cpp index c48ed657..c80459b8 100644 --- a/src/fileiter.cpp +++ b/src/fileiter.cpp @@ -832,7 +832,7 @@ bool iswild(const char* mask, const char* name) ++mask; continue; } - // fall through: + // fall through default: if(BOOST_REGEX_FI_TRANSLATE(*mask) != BOOST_REGEX_FI_TRANSLATE(*name)) return false; diff --git a/src/icu.cpp b/src/icu.cpp index d101d65d..5f249e2d 100644 --- a/src/icu.cpp +++ b/src/icu.cpp @@ -481,7 +481,7 @@ icu_regex_traits::string_type icu_regex_traits::lookup_collatename(const char_ty bool icu_regex_traits::isctype(char_type c, char_class_type f) const { // check for standard catagories first: - char_class_type m = char_class_type(1uLL << u_charType(c)); + char_class_type m = char_class_type(static_cast(1) << u_charType(c)); if((m & f) != 0) return true; // now check for special cases: diff --git a/test/c_compiler_checks/posix_api_check.c b/test/c_compiler_checks/posix_api_check.c index c12525c8..34abca14 100644 --- a/test/c_compiler_checks/posix_api_check.c +++ b/test/c_compiler_checks/posix_api_check.c @@ -39,7 +39,7 @@ int main() { char buf[256]; regerrorA(result, &re, buf, sizeof(buf)); - printf(buf); + puts(buf); return result; } assert(re.re_nsub == 0); @@ -50,7 +50,7 @@ int main() { char buf[256]; regerrorA(result, &re, buf, sizeof(buf)); - printf(buf); + puts(buf); regfreeA(&re); return result; } diff --git a/test/c_compiler_checks/wide_posix_api_check.c b/test/c_compiler_checks/wide_posix_api_check.c index 096d929a..cd1a287d 100644 --- a/test/c_compiler_checks/wide_posix_api_check.c +++ b/test/c_compiler_checks/wide_posix_api_check.c @@ -50,7 +50,7 @@ int main() regerror(result, &re, buf, sizeof(buf)); for(i = 0; i < 256; ++i) nbuf[i] = (char)(buf[i]); - printf(nbuf); + puts(nbuf); return result; } if(re.re_nsub != 0) @@ -66,7 +66,7 @@ int main() regerror(result, &re, buf, sizeof(buf)); for(i = 0; i < 256; ++i) nbuf[i] = (char)(buf[i]); - printf(nbuf); + puts(nbuf); regfree(&re); return result; } diff --git a/test/captures/captures_test.cpp b/test/captures/captures_test.cpp index 63f58c9c..641d1b9b 100644 --- a/test/captures/captures_test.cpp +++ b/test/captures/captures_test.cpp @@ -29,9 +29,9 @@ #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) template -int array_size(const char* (&p)[N]) +size_t array_size(const char* (&p)[N]) { - for(int i = 0; i < N; ++i) + for(size_t i = 0; i < N; ++i) if(p[i] == 0) return i; return N; diff --git a/test/test_macros.hpp b/test/test_macros.hpp index d8772965..ef28fe0a 100644 --- a/test/test_macros.hpp +++ b/test/test_macros.hpp @@ -65,8 +65,8 @@ void report_unexpected_exception(const E& e, int severity, const char* file, int } #define BOOST_MP_UNEXPECTED_EXCEPTION_CHECK(severity) \ - catch(const std::exception& e) \ - { report_unexpected_exception(e, severity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); }\ + catch(const std::exception& __e) \ + { report_unexpected_exception(__e, severity, __FILE__, __LINE__, BOOST_CURRENT_FUNCTION); }\ catch(...)\ { BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Exception of unknown type was thrown" << std::endl; report_severity(severity); } diff --git a/test/unicode/unicode_iterator_test.cpp b/test/unicode/unicode_iterator_test.cpp index 243ef742..2e6bcec1 100644 --- a/test/unicode/unicode_iterator_test.cpp +++ b/test/unicode/unicode_iterator_test.cpp @@ -157,22 +157,30 @@ void spot_checks() void test(const std::vector< ::boost::uint32_t>& v) { typedef std::vector< ::boost::uint32_t> vector32_type; +#ifdef TEST_UTF16 typedef std::vector< ::boost::uint16_t> vector16_type; +#endif typedef std::vector< ::boost::uint8_t> vector8_type; +#ifdef TEST_UTF16 typedef boost::u32_to_u16_iterator u32to16type; typedef boost::u16_to_u32_iterator u16to32type; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR) && !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) typedef std::reverse_iterator ru32to16type; typedef std::reverse_iterator ru16to32type; #endif +#endif // TEST_UTF16 +#ifdef TEST_UTF8 typedef boost::u32_to_u8_iterator u32to8type; typedef boost::u8_to_u32_iterator u8to32type; #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION) && !defined(BOOST_NO_STD_ITERATOR) && !defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) typedef std::reverse_iterator ru32to8type; typedef std::reverse_iterator ru8to32type; #endif +#endif // TEST_UTF8 vector8_type v8; +#ifdef TEST_UTF16 vector16_type v16; +#endif vector32_type v32; vector32_type::const_iterator i, j, k; From 231dbc3ebfc253316ac2ed1d2e175cac0404dfc2 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 21 Jul 2018 15:19:41 +0100 Subject: [PATCH 19/24] Correct behaviour of \b when matching null-strings. See https://github.com/boostorg/regex/issues/40 --- .../boost/regex/v4/perl_matcher_common.hpp | 6 +++-- test/regress/test_escapes.cpp | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/include/boost/regex/v4/perl_matcher_common.hpp b/include/boost/regex/v4/perl_matcher_common.hpp index a0973da9..94cb14e6 100644 --- a/include/boost/regex/v4/perl_matcher_common.hpp +++ b/include/boost/regex/v4/perl_matcher_common.hpp @@ -476,12 +476,14 @@ bool perl_matcher::match_word_boundary() } else { - b = (m_match_flags & match_not_eow) ? true : false; + if (m_match_flags & match_not_eow) + return false; + b = false; } if((position == backstop) && ((m_match_flags & match_prev_avail) == 0)) { if(m_match_flags & match_not_bow) - b ^= true; + return false; else b ^= false; } diff --git a/test/regress/test_escapes.cpp b/test/regress/test_escapes.cpp index 2511fcfe..afefc97a 100644 --- a/test/regress/test_escapes.cpp +++ b/test/regress/test_escapes.cpp @@ -169,5 +169,30 @@ void test_assertion_escapes() TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2)); TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2)); } + // Bug report: https://github.com/boostorg/regex/issues/40 + TEST_REGEX_SEARCH("\\b", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\b", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\<", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "", match_not_bow | match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_default, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_eow, make_array(-2, -2)); + TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); } From 2517588955143d30cdbc89b8890af3af89fdccef Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 22 Jul 2018 11:26:33 +0100 Subject: [PATCH 20/24] Fix \R when no_escapes_in_list flag is set. Fixes: https://github.com/boostorg/regex/issues/57 --- .../boost/regex/v4/regex_traits_defaults.hpp | 21 ++++++++++--------- test/regress/test_escapes.cpp | 18 ++++++++++++++++ 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/include/boost/regex/v4/regex_traits_defaults.hpp b/include/boost/regex/v4/regex_traits_defaults.hpp index df9922df..87030a83 100644 --- a/include/boost/regex/v4/regex_traits_defaults.hpp +++ b/include/boost/regex/v4/regex_traits_defaults.hpp @@ -39,6 +39,7 @@ #include #endif #include +#include #ifdef BOOST_NO_STDC_NAMESPACE namespace std{ @@ -327,17 +328,17 @@ boost::intmax_t global_toi(const charT*& p1, const charT* p2, int radix, const t } template -inline const charT* get_escape_R_string() +inline typename boost::enable_if_c<(sizeof(charT) > 1), const charT*>::type get_escape_R_string() { #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable:4309 4245) #endif - static const charT e1[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?', - '|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', static_cast('\x85'), '\\', 'x', '{', '2', '0', '2', '8', '}', - '\\', 'x', '{', '2', '0', '2', '9', '}', ']', ')', '\0' }; - static const charT e2[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?', - '|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', static_cast('\x85'), ']', ')', '\0' }; + static const charT e1[] = { '(', '?', '-', 'x', ':', '(', '?', '>', '\x0D', '\x0A', '?', + '|', '[', '\x0A', '\x0B', '\x0C', static_cast(0x85), static_cast(0x2028), + static_cast(0x2029), ']', ')', ')', '\0' }; + static const charT e2[] = { '(', '?', '-', 'x', ':', '(', '?', '>', '\x0D', '\x0A', '?', + '|', '[', '\x0A', '\x0B', '\x0C', static_cast(0x85), ']', ')', ')', '\0' }; charT c = static_cast(0x2029u); bool b = (static_cast(c) == 0x2029u); @@ -348,15 +349,15 @@ inline const charT* get_escape_R_string() #endif } -template <> -inline const char* get_escape_R_string() +template +inline typename boost::disable_if_c<(sizeof(charT) > 1), const charT*>::type get_escape_R_string() { #ifdef BOOST_MSVC # pragma warning(push) # pragma warning(disable:4309) #endif - static const char e2[] = { '(', '?', '>', '\\', 'x', '0', 'D', '\\', 'x', '0', 'A', '?', - '|', '[', '\\', 'x', '0', 'A', '\\', 'x', '0', 'B', '\\', 'x', '0', 'C', '\\', 'x', '8', '5', ']', ')', '\0' }; + static const charT e2[] = { '(', '?', '-', 'x', ':', '(', '?', '>', '\x0D', '\x0A', '?', + '|', '[', '\x0A', '\x0B', '\x0C', '\x85', ']', ')', ')', '\0' }; return e2; #ifdef BOOST_MSVC # pragma warning(pop) diff --git a/test/regress/test_escapes.cpp b/test/regress/test_escapes.cpp index afefc97a..c9bc951b 100644 --- a/test/regress/test_escapes.cpp +++ b/test/regress/test_escapes.cpp @@ -194,5 +194,23 @@ void test_assertion_escapes() TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow, make_array(-2, -2)); TEST_REGEX_SEARCH("\\>", perl, "-", match_not_eow, make_array(-2, -2)); TEST_REGEX_SEARCH("\\>", perl, "-", match_not_bow | match_not_eow, make_array(-2, -2)); + // Bug report https://github.com/boostorg/regex/issues/57 + // Line ending \R: + TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\nbar", match_default, make_array(3, 4, -2, -2)); + TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\rbar", match_default, make_array(3, 4, -2, -2)); + TEST_REGEX_SEARCH("\\R", perl | no_escape_in_lists, "foo\r\nbar", match_default, make_array(3, 5, -2, -2)); + TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\r\nbar", match_default, make_array(0, 5, -2, -2)); + TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\012bar", match_default, make_array(0, 4, -2, -2)); + TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\013bar", match_default, make_array(0, 4, -2, -2)); + TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\013bar", match_default, make_array(0, 4, -2, -2)); + TEST_REGEX_SEARCH("(?x) abc \\R", perl | no_escape_in_lists, "abc\205bar", match_default, make_array(0, 4, -2, -2)); + // see if \u works: + if(*w == 0x2028u) + { + TEST_REGEX_SEARCH_W(L"\\R", perl | no_escape_in_lists, L"foo\u2028bar", match_default, make_array(3, 4, -2, -2)); + TEST_REGEX_SEARCH_W(L"\\R", perl | no_escape_in_lists, L"foo\u2029bar", match_default, make_array(3, 4, -2, -2)); + TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl | no_escape_in_lists, L"abc\u2028bar", match_default, make_array(0, 4, -2, -2)); + TEST_REGEX_SEARCH_W(L"(?x) abc \\R", perl | no_escape_in_lists, L"abc\u2029bar", match_default, make_array(0, 4, -2, -2)); + } } From 7b2ccc00959a619919855692c79868e0e8b11244 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 22 Jul 2018 17:16:21 +0100 Subject: [PATCH 21/24] Tentative fix for msvc warnings. See https://github.com/boostorg/regex/issues/61. Adds warning test case. --- include/boost/regex/config.hpp | 5 ++++- include/boost/regex/v4/basic_regex.hpp | 8 +++++++- include/boost/regex/v4/basic_regex_creator.hpp | 4 +++- include/boost/regex/v4/basic_regex_parser.hpp | 5 ++++- include/boost/regex/v4/instances.hpp | 5 ++++- include/boost/regex/v4/match_results.hpp | 5 ++++- include/boost/regex/v4/perl_matcher.hpp | 9 +++++++-- include/boost/regex/v4/perl_matcher_common.hpp | 4 +++- .../boost/regex/v4/perl_matcher_non_recursive.hpp | 5 ++++- include/boost/regex/v4/regex_raw_buffer.hpp | 6 +++--- include/boost/regex/v4/regex_split.hpp | 4 +++- include/boost/regex/v4/regex_traits_defaults.hpp | 2 +- include/boost/regex/v4/w32_regex_traits.hpp | 2 ++ test/Jamfile.v2 | 5 +++++ test/test_warnings.cpp | 12 ++++++++++++ 15 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 test/test_warnings.cpp diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index eb998110..1df0097d 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -201,7 +201,10 @@ # define BOOST_REGEX_HAS_OTHER_WCHAR_T # ifdef BOOST_MSVC # pragma warning(push) -# pragma warning(disable : 4251 4231) +# pragma warning(disable : 4251) +#if BOOST_MSVC < 1700 +# pragma warning(disable : 4231) +#endif # if BOOST_MSVC < 1600 # pragma warning(disable : 4660) # endif diff --git a/include/boost/regex/v4/basic_regex.hpp b/include/boost/regex/v4/basic_regex.hpp index ac91af29..19623720 100644 --- a/include/boost/regex/v4/basic_regex.hpp +++ b/include/boost/regex/v4/basic_regex.hpp @@ -36,10 +36,16 @@ namespace boost{ #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable : 4251 4231 4800) +#pragma warning(disable : 4251) +#if BOOST_MSVC < 1700 +# pragma warning(disable : 4231) +#endif #if BOOST_MSVC < 1600 #pragma warning(disable : 4660) #endif +#if BOOST_MSVC < 1910 +#pragma warning(disable:4800) +#endif #endif namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v4/basic_regex_creator.hpp b/include/boost/regex/v4/basic_regex_creator.hpp index 623e06f1..7c006527 100644 --- a/include/boost/regex/v4/basic_regex_creator.hpp +++ b/include/boost/regex/v4/basic_regex_creator.hpp @@ -33,7 +33,9 @@ #ifdef BOOST_MSVC # pragma warning(push) -# pragma warning(disable: 4800) +#if BOOST_MSVC < 1910 +#pragma warning(disable:4800) +#endif #endif namespace boost{ diff --git a/include/boost/regex/v4/basic_regex_parser.hpp b/include/boost/regex/v4/basic_regex_parser.hpp index dc528a39..6c7065f0 100644 --- a/include/boost/regex/v4/basic_regex_parser.hpp +++ b/include/boost/regex/v4/basic_regex_parser.hpp @@ -35,7 +35,10 @@ namespace BOOST_REGEX_DETAIL_NS{ #ifdef BOOST_MSVC #pragma warning(push) -#pragma warning(disable:4244 4800) +#pragma warning(disable:4244) +#if BOOST_MSVC < 1910 +#pragma warning(disable:4800) +#endif #endif inline boost::intmax_t umax(mpl::false_ const&) diff --git a/include/boost/regex/v4/instances.hpp b/include/boost/regex/v4/instances.hpp index 05ac71a6..b70437e7 100644 --- a/include/boost/regex/v4/instances.hpp +++ b/include/boost/regex/v4/instances.hpp @@ -84,7 +84,10 @@ template class BOOST_REGEX_DECL ::boost::BOOST_REGEX_DETAIL_NS::perl_matcher(ptr) - static_cast(data()); + return size_type(static_cast(ptr) - static_cast(data())); } void BOOST_REGEX_CALL clear() diff --git a/include/boost/regex/v4/regex_split.hpp b/include/boost/regex/v4/regex_split.hpp index 65b2c64a..afa56598 100644 --- a/include/boost/regex/v4/regex_split.hpp +++ b/include/boost/regex/v4/regex_split.hpp @@ -36,7 +36,9 @@ namespace boost{ #ifdef BOOST_MSVC # pragma warning(push) -# pragma warning(disable: 4800) +#if BOOST_MSVC < 1910 +#pragma warning(disable:4800) +#endif #endif namespace BOOST_REGEX_DETAIL_NS{ diff --git a/include/boost/regex/v4/regex_traits_defaults.hpp b/include/boost/regex/v4/regex_traits_defaults.hpp index 87030a83..e58d6bae 100644 --- a/include/boost/regex/v4/regex_traits_defaults.hpp +++ b/include/boost/regex/v4/regex_traits_defaults.hpp @@ -241,7 +241,7 @@ inline std::ptrdiff_t global_length(const char* p) template<> inline std::ptrdiff_t global_length(const wchar_t* p) { - return (std::wcslen)(p); + return (std::ptrdiff_t)(std::wcslen)(p); } #endif template diff --git a/include/boost/regex/v4/w32_regex_traits.hpp b/include/boost/regex/v4/w32_regex_traits.hpp index bf996d61..378ee856 100644 --- a/include/boost/regex/v4/w32_regex_traits.hpp +++ b/include/boost/regex/v4/w32_regex_traits.hpp @@ -51,8 +51,10 @@ #ifdef BOOST_MSVC #pragma warning(push) #pragma warning(disable:4786) +#if BOOST_MSVC < 1910 #pragma warning(disable:4800) #endif +#endif namespace boost{ diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index f485058c..17f6b842 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -196,3 +196,8 @@ build-project ../example ; # `quick` target (for CI) run quick.cpp ../build//boost_regex ; + +compile test_warnings.cpp + : msvc:all msvc:on + gcc:all gcc:on + clang:all clang:on ; diff --git a/test/test_warnings.cpp b/test/test_warnings.cpp new file mode 100644 index 00000000..1c2a41d3 --- /dev/null +++ b/test/test_warnings.cpp @@ -0,0 +1,12 @@ +#ifdef _MSC_VER +#pragma warning(disable:4820 4668) +#endif + +#include + +void test_proc() +{ + std::string text, re; + boost::regex exp(re); + regex_match(text, exp); +} \ No newline at end of file From 5177518fe3ed1f93c1432f4b96d8cb5d673d1be1 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sun, 22 Jul 2018 18:25:35 +0100 Subject: [PATCH 22/24] Fix missing \n at end of file, Fix some clang warnings. Add gcc 7&8 to CI tests. --- .travis.yml | 36 ++++++++++++++++++++++++++++ include/boost/regex/v4/instances.hpp | 2 ++ test/test_warnings.cpp | 19 ++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ae6c5e50..4b1ab15e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -102,6 +102,42 @@ matrix: sources: - ubuntu-toolchain-r-test + - os: linux + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=03,11 CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-7 CXXSTD=14,1z CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=03,11 CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-8 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: TOOLSET=gcc COMPILER=g++-8 CXXSTD=14,1z CXXSTD_DIALECT=cxxstd-dialect=gnu + addons: + apt: + packages: + - g++-8 + sources: + - ubuntu-toolchain-r-test + - os: linux env: TOOLSET=clang COMPILER=clang++ CXXSTD=03,11 diff --git a/include/boost/regex/v4/instances.hpp b/include/boost/regex/v4/instances.hpp index b70437e7..f695f01a 100644 --- a/include/boost/regex/v4/instances.hpp +++ b/include/boost/regex/v4/instances.hpp @@ -124,8 +124,10 @@ template class BOOST_REGEX_TEMPLATE_DECL ::boost::BOOST_REGEX_DETAIL_NS::perl_ma #ifdef __clang__ #pragma clang diagnostic push +#if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ > 5)) #pragma clang diagnostic ignored "-Wkeyword-macro" #endif +#endif # ifndef BOOST_REGEX_INSTANTIATE # ifdef __GNUC__ diff --git a/test/test_warnings.cpp b/test/test_warnings.cpp index 1c2a41d3..f85d437d 100644 --- a/test/test_warnings.cpp +++ b/test/test_warnings.cpp @@ -1,7 +1,23 @@ +/* +* +* Copyright (c) 2018 +* John Maddock +* +* Use, modification and distribution are subject to the +* Boost Software License, Version 1.0. (See accompanying file +* LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +* +*/ + + #ifdef _MSC_VER #pragma warning(disable:4820 4668) #endif +#ifdef __APPLE_CC__ +#pragma clang diagnostic ignored "-Wc++11-long-long" +#endif + #include void test_proc() @@ -9,4 +25,5 @@ void test_proc() std::string text, re; boost::regex exp(re); regex_match(text, exp); -} \ No newline at end of file +} + From f5b7d3a4f9e927fc632a1c1ea694b14baefe3a7a Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Mon, 23 Jul 2018 19:10:47 +0100 Subject: [PATCH 23/24] Correct apple clang version check. --- include/boost/regex/v4/instances.hpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/include/boost/regex/v4/instances.hpp b/include/boost/regex/v4/instances.hpp index f695f01a..0e423437 100644 --- a/include/boost/regex/v4/instances.hpp +++ b/include/boost/regex/v4/instances.hpp @@ -122,11 +122,17 @@ template class BOOST_REGEX_TEMPLATE_DECL ::boost::BOOST_REGEX_DETAIL_NS::perl_ma #elif (defined(__GNUC__) && (__GNUC__ >= 3)) || !defined(BOOST_NO_CXX11_EXTERN_TEMPLATE) -#ifdef __clang__ -#pragma clang diagnostic push -#if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ > 5)) -#pragma clang diagnostic ignored "-Wkeyword-macro" -#endif +#if defined(__clang__) +# pragma clang diagnostic push +# if defined(__APPLE_CC__) +# if (__clang_major__ > 6) +# pragma clang diagnostic ignored "-Wkeyword-macro" +# endif +# else +# if (__clang_major__ > 3) || ((__clang_major__ == 3) && (__clang_minor__ > 5)) +# pragma clang diagnostic ignored "-Wkeyword-macro" +# endif +# endif #endif # ifndef BOOST_REGEX_INSTANTIATE From 40ecdc3f8b52cc6833f05b37610e916824ba88c7 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Sat, 25 Aug 2018 18:05:18 +0100 Subject: [PATCH 24/24] Disable template instantiation for Clang: it breaks with -fvisibility=hidden --- include/boost/regex/config.hpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/boost/regex/config.hpp b/include/boost/regex/config.hpp index 1df0097d..de817dbf 100644 --- a/include/boost/regex/config.hpp +++ b/include/boost/regex/config.hpp @@ -113,6 +113,13 @@ #if defined(__MINGW32__) # define BOOST_REGEX_NO_EXTERNAL_TEMPLATES #endif +/* + * Clang fails to export template instances with -fvisibility=hidden, see + * https://github.com/boostorg/regex/issues/49 + */ +#ifdef __clang__ +# define BOOST_REGEX_NO_EXTERNAL_TEMPLATES +#endif /* * If there isn't good enough wide character support then there will