Skip to content

Commit 524956e

Browse files
committed
fix issue #232
1 parent ccc5608 commit 524956e

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

include/boost/regex/v5/perl_matcher.hpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,34 @@
3939
#endif
4040
#endif
4141

42+
#ifndef BOOST_REGEX_STANDALONE
43+
# define BOOST_REGEX_DETAIL_THROW(msg) boost::throw_exception(std::logic_error(msg))
44+
#else
45+
# define BOOST_REGEX_DETAIL_THROW(msg) throw std::logic_error(msg)
46+
#endif
47+
4248
namespace boost{
4349
namespace BOOST_REGEX_DETAIL_NS{
4450

4551
//
4652
// error checking API:
4753
//
48-
inline void verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf)
54+
inline void verify_options(boost::regex_constants::syntax_option_type, match_flag_type mf)
4955
{
56+
auto is_perl = (mf & match_perl);
57+
auto is_posix = (mf & match_posix);
58+
59+
if (is_perl && is_posix)
60+
{
61+
BOOST_REGEX_DETAIL_THROW("Usage Error: Can't mix Perl and POSIX matching rules");
62+
}
63+
5064
//
5165
// can't mix match_extra with POSIX matching rules:
5266
//
53-
if ((mf & match_extra) && (mf & match_posix))
67+
if ((mf & match_extra) && is_posix)
5468
{
55-
std::logic_error msg("Usage Error: Can't mix regular expression captures with POSIX matching rules");
56-
#ifndef BOOST_REGEX_STANDALONE
57-
throw_exception(msg);
58-
#else
59-
throw msg;
60-
#endif
69+
BOOST_REGEX_DETAIL_THROW("Usage Error: Can't mix regular expression captures with POSIX matching rules");
6170
}
6271
}
6372
//

include/boost/regex/v5/perl_matcher_common.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,7 @@ void perl_matcher<BidiIterator, Allocator, traits>::construct_init(const basic_r
6060
if(e.empty())
6161
{
6262
// precondition failure: e is not a valid regex.
63-
std::invalid_argument ex("Invalid regular expression object");
64-
#ifndef BOOST_REGEX_STANDALONE
65-
boost::throw_exception(ex);
66-
#else
67-
throw e;
68-
#endif
63+
BOOST_REGEX_DETAIL_THROW("Invalid regular expression object");
6964
}
7065
pstate = 0;
7166
m_match_flags = f;
@@ -98,7 +93,11 @@ void perl_matcher<BidiIterator, Allocator, traits>::construct_init(const basic_r
9893
match_any_mask = static_cast<unsigned char>((f & match_not_dot_newline) ? BOOST_REGEX_DETAIL_NS::test_not_newline : BOOST_REGEX_DETAIL_NS::test_newline);
9994
// Disable match_any if requested in the state machine:
10095
if(e.get_data().m_disable_match_any)
96+
{
97+
if (m_match_flags & match_posix)
98+
BOOST_REGEX_DETAIL_THROW("Invalid regex for POSIX-style matching");
10199
m_match_flags &= regex_constants::match_not_any;
100+
}
102101
}
103102
#ifdef BOOST_REGEX_MSVC
104103
# pragma warning(pop)

0 commit comments

Comments
 (0)