Hi all

I have come across a bug associated with lexical_cast and regex (though the culprit may well be the Visual C++ compiler). I have stripped the code to the bare essentials. This worked OK under VC++ 8 (2005), but gives an access violation under VC++ 9 (2008). This occurs with both boost 1.39 and 1.42.

Simplified code follows:

#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0

#include <boost/lexical_cast.hpp>
#include <boost/regex.hpp>

#include <string>
#include <iostream>

void violate()
{
        int i = 0;
        std::string x = "x" + boost::lexical_cast<std::string>(i);
        boost::regex regex("aaa");
        boost::regex_replace(x, regex, "bbb", boost::match_default);
}
int main()
{
        violate();

        std::cout << "Enter to exit\n";
        std::cin.get();
}

In debug mode, the following exception message is generated:

Unhandled exception at 0x10487b3f (msvcp90d.dll) in RegexBug.exe: 0xC0000005: Access violation writing location 0xcccccccc.

Stack at time of exception is:

msvcp90d.dll!std::_Container_base_secure::_Orphan_all()  Line 223 + 0x5 bytes        C++
msvcp90d.dll!std::_Container_base_secure::~_Container_base_secure()  Line 115        C++
msvcp90d.dll!std::_String_base::~_String_base()  + 0x11 bytes        C++
msvcp90d.dll!std::_String_val<unsigned short,std::allocator<unsigned short> >::~_String_val<unsigned short,std::allocator<unsigned short> >()  + 0x11 bytes        C++
msvcp90d.dll!std::basic_string<char,std::char_traits<char>,std::allocator<char> >::~basic_string<char,std::char_traits<char>,std::allocator<char> >()  Line 917 + 0xf bytes        C++
RegexBug.exe!violate()  Line 16 + 0x1e bytes        C++
RegexBug.exe!main()  Line 21        C++
RegexBug.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes        C
RegexBug.exe!mainCRTStartup()  Line 403        C
kernel32.dll!7c817067()        
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]        
While I have found several work-arounds, it would be useful to log this, if it is a bug, in the correct place - boost? MS?

Appologies for the extended junk at the end of this email!

John
John Foster

Senior Quantitative Credit Developer
Model Development, Group Credit Portfolio & Models
National Australia Bank

Level 15, 500 Bourke St, Melbourne VIC 3000
Tel: +61 (0)3 8641 5228
Email:  John.X.Foster@nab.com.au


This e-mail is sent by or on behalf of the named sender identified above.
If:

(a) you do not wish to receive any e-mail marketing material from this person in the future, please forward the contents of this email to unsubscribe@nab.com.au with the word "unsubscribe" in the subject box.

(b) you wish to unsubscribe from all central e-mail marketing lists used by our business, please forward the contents of this e-mail to unsubscribeall@nab.com.au with the message "unsubscribe from a ll central e-mail marketing lists" in the subject box.

If you do not forward the contents of this e-mail with your unsubscription then it may not be able to be implemented.

The information contained in this e-mail communication may be confidential. You should only read, disclose, re-transmit, copy, distribute, act in reliance on or commercialise the information if you are authorised to do so. If you are not the intended recipient of this e-mail communication, please immediately notify us by e-mail to postmaster@nab.com.au, or reply by e-mail direct t o the sender and then destroy any electronic and paper copy of this message. Any views expressed in this e-mail communication are those of the individual sender, except where the sender specifically states them to be the views of a member of the National Australia Bank Group of companies. Any advice contained in this e-mail has been prepared without taking into account your objectives, financial situation or needs. Before acting on any advice in this e-mail, National Australia Bank Limited recommends that you consider whether it is appropriate for your circumstances. If this e-mail contains reference to any financial products, the National recommends you consider the Product Disclosure Statement (PDS) or other disclosure document before making any decisions regarding any products. The National Australia Bank Group of companies does not represent, warrant or guarantee that the integrity of this communication has been maintained nor that the communication is free of errors, virus or interference.