I now know that this is an invalid usage, after I know that 'smatch' is based on iterators. Since 'smatch' does not encover in the docs what internal structure it has, I did not conclude that it is based on iterators. And a string const& as param does not mean for me, that this string should be valid later on. May be I am wrong.

BTW: the trick with volatile does not work in MSVC 8.0 Express compiler. :( Would be great if the upcoming standard would provide a temporary checking facility ;)

Many thanks for the great lib and your time!
Ovanes

On 10/16/07, Eric Niebler <eric@boost-consulting.com> wrote:
Ovanes Markarian wrote:
> Hello Eric,
>
> this code fragment will crash, since 'what' uses iterators into the
> invalid string
>
>         x::smatch what;
>         if(x::regex_match(std::string("      (some_type_ptr) xyz,"),
> what, regex)) //string goes out of scope after this sentance
>         {
>             std::cout << what[0] << endl; // boom! string iterators are
> no longer valid
>             std::cout << what[1] << endl;
>         }
>
> May be there is a way to probit this kind of behaviour during the
> compilation or at least this can be stated in the docs...


As I'm sure you know, this is an invalid use. It couldn't hurt to be
explicit about it in the docs, though.

FWIW, I once found a way to disallow code like this at compile time.
This regex_match() overload takes a "std::string const &", which accepts
temporaries. It could instead take a "std::string const volatile &"
which would *not* bind to temporaries, and then I can cast away the
volatile. But it seems like a dirty trick, so I haven't done it.

--
Eric Niebler
Boost Consulting
www.boost-consulting.com

_______________________________________________
Boost-users mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users