Boost::regex assign/operator= 'problem'

Should an empty boost::regex raise a 'bad expression' exception when you assign it to another boost::regex object? It seems to me that an empty expression can't be bad - it hasn't had the chance to be good OR bad yet :-) The rationale for this is that I have an object that contains a boost::regex that is compiled on demand. The object is likely to be copied (into a std::vector), before the regex has been compiled (if it is ever compiled). I know I could use things like boost::optional<boost::regex>, or boost::scoped_ptr<boost::regex> (I am working round it currently), but this seems like an interesting corner case! Here's a minimal sample: #include <iostream> #include <boost/regex.hpp> int main(int, char**) { boost::regex re; try { re = boost::regex(); } catch (boost::bad_expression&) { std::cout << "It threw\n"; } return 0; } It'll output "It threw" on execution (environment = Windows 2000, VC7.1, Boost1.32.0). Stuart Dootson

Should an empty boost::regex raise a 'bad expression' exception when you assign it to another boost::regex object? It seems to me that an empty expression can't be bad - it hasn't had the chance to be good OR bad yet :-)
It's basically a bug : and it's fixed in 1.33. Copying will also be a lot less expensive in 1.33 since it uses copy-on-write. John.

On 7/1/05, John Maddock <john@johnmaddock.co.uk> wrote:
Should an empty boost::regex raise a 'bad expression' exception when you assign it to another boost::regex object? It seems to me that an empty expression can't be bad - it hasn't had the chance to be good OR bad yet :-)
It's basically a bug : and it's fixed in 1.33. Copying will also be a lot less expensive in 1.33 since it uses copy-on-write.
John.
Cool - thanks! Stuart
participants (2)
-
John Maddock
-
Stuart Dootson