What misconfiguration might cause Boost Filesystem to fail with an access violation when compiled for Debug model under Visual Studio 2019?


I am struggling to understand why some of my code using boost, which was working fine under Visual Studio 2017, is now resulting in an access violation under Visual Studio 2019. However, I only encounter this failure under Debug build. Release build works fine, with no issues.

What could I have set up incorrectly in my build, environment, or code, that could cause such a failure?

My environment:

  • Windows 10
  • Boost 1.74 (dynamic link)
  • Visual Studio 2019 v16.7.6
  • Compiling for C++ x64

The failing line of my code is this:

boost::filesystem::path dir = (boost::filesystem::temp_directory_path() / boost::filesystem::unique_path("%%%%-%%%%-%%%%-%%%%"));

The failing line in Boost filesystem is this here in boost/filesystem/path.hpp:

namespace path_traits
{  //  without codecvt

    void convert(const char* from,
    const char* from_end,    // 0 for null terminated MBCS
    std::wstring & to)
    convert(from, from_end, to, path::codecvt());

The failure message reported by Visual Studio is as follows:

Exception thrown at 0x00007FF9164F1399 (vcruntime140d.dll) in ezv8.tests.exe: 0xC0000005: Access violation reading location 0xFFFFFFFFFFFFFFFF.

The call stack looks like this:

    vcruntime140d.dll!00007ff9164f1550()    Unknown
>   boost_filesystem-vc142-mt-gd-x64-1_74.dll!wmemmove(wchar_t * _S1, const wchar_t * _S2, unsigned __int64 _N) Line 248    C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::_WChar_traits<wchar_t>::move(wchar_t * const _First1, const wchar_t * const _First2, const unsigned __int64 _Count) Line 204 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::wstring::append(const wchar_t * const _Ptr, const unsigned __int64 _Count) Line 2864 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!std::wstring::append<wchar_t *,0>(wchar_t * const _First, wchar_t * const _Last) Line 2916    C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!`anonymous namespace'::convert_aux(const char * from, const char * from_end, wchar_t * to, wchar_t * to_end, std::wstring & target, const std::codecvt<wchar_t,char,_Mbstatet> & cvt) Line 77 C++
    boost_filesystem-vc142-mt-gd-x64-1_74.dll!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::wstring & to, const std::codecvt<wchar_t,char,_Mbstatet> & cvt) Line 153   C++
    appsvcs.dll!boost::filesystem::path_traits::convert(const char * from, const char * from_end, std::wstring & to) Line 1006  C++
    appsvcs.dll!boost::filesystem::path_traits::dispatch<std::wstring>(const std::string & c, std::wstring & to) Line 257   C++
    appsvcs.dll!boost::filesystem::path::path<char [20]>(const char[20] & source, void * __formal) Line 168 C++

I use UTF-8 strings throughout my code, so I have configured boost::filesystem to expect UTF-8 strings as follows:


asked on Stack Overflow Nov 16, 2020 by Boinst

1 Answer


The cause of this issue turned out to be inconsistent use of _ITERATOR_DEBUG_LEVEL. This setting does affect ABI compatibility. I was setting this flag (to 0) in my own code, but it was not set in the Boost build. The solution is to either remove the flag from one's own code, or add the flag to the Boost build by adding define=_ITERATOR_DEBUG_LEVEL=0 to the b2 arguments (from another stack overflow answer).

answered on Stack Overflow Nov 20, 2020 by Boinst

User contributions licensed under CC BY-SA 3.0