2

I just installed the boost lib and visual studio on my new laptop.

I'm getting the following error while trying to run my code:

Assertion failed: r != 0, file libs\regex\build\..\src\w32_regex_traits.cpp, line 125

The error occurs when running in debug 32bit, but works when using release instead of debug. This is my snippet:

#include <iostream>
#include <boost/regex.hpp>
int main()
{
     boost::regex("hello word", boost::regex::icase);
}

I tried to re-install VS2019 and the boost lib, but the problem persists.

Any ideas what could be the cause of the error?

sehe
  • 374,641
  • 47
  • 450
  • 633
cdo-dev
  • 21
  • 1
  • 1
    *I tried to re-install VS2019 and the boost lib* -- There is no need to reinstall compilers or libraries. The error is an `assertion`, not a crash. Because it is an assertion, the library knows exactly why the assertion was given. All you had to do is debug and see where the assertion takes place and why it was given. **How** to fix the problem is a different story, but reinstalling compilers, libraries, etc. was totally unnecessary for this issue. – PaulMcKenzie Jul 03 '20 at 23:44

3 Answers3

1

The assert is here:

#ifndef BOOST_NO_ANSI_APIS
   int r = ::LCMapStringA(this->m_locale, LCMAP_LOWERCASE, char_map, 1 << CHAR_BIT, this->m_lower_map, 1 << CHAR_BIT);
   BOOST_ASSERT(r != 0);
#else

It looks like LCMapStringA function fails.

This function returns 0 if it does not succeed. To get extended error information, the application can call GetLastError, which can return one of the following error codes:

  • ERROR_INSUFFICIENT_BUFFER. A supplied buffer size was not large enough, or it was incorrectly set to NULL.
  • ERROR_INVALID_FLAGS. The values supplied for flags were not valid.
  • ERROR_INVALID_PARAMETER. Any of the parameter values was invalid.

I do not think these conditions are ignorable. They might lead to Undefined Behavior. So, perhaps you can use the debugger to get the value of GetLastError at the point when it failed to get more information.

Depending on the kind of failure you

  • fix your system config (perhaps locale support is missing?)
  • fix your input (perhaps your input contains invalid encoding)
  • report a bug to the boost devs (in case there is a buffer sizing issue that is not a documented limitation)
sehe
  • 374,641
  • 47
  • 450
  • 633
0

After changing the regional format from English(XXXX) region to English (United State) issue was resolved

cdo-dev
  • 21
  • 1
0

I got the same assertion crash under Windows and was able to fix it by defining BOOST_REGEX_NO_W32.

sakra
  • 62,199
  • 16
  • 168
  • 151