<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - regex: regex_replace does not handle \b correctly"
   href="http://llvm.org/bugs/show_bug.cgi?id=16240">16240</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>regex: regex_replace does not handle \b correctly
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>hhinnant@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>buglibcxx@lancom.de
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Example from cplusplus.org reference:

  std::string s ("there is a subsequence in the string\n");
  std::regex e ("\\b(sub)([^ ]*)");   // matches words beginning by "sub"

  // using string/c-string (3) version:
  std::cout << std::regex_replace (s,e,"sub-$2");

Testing this with valgrind results in the message: "Invalid read of size 1"

This is because of setting match_prev_avail-flag in a case when we are at the
beginning of a string. This leads to a read operation one byte before the
beginning of the string in "__word_boundary<_CharT, _Traits>::__exec(__state&
__s) const"
The flag is set in "regex_iterator<BidirectionalIterator, _CharT,
_Traits>::operator++()" called from "regex_replace(_OutputIterator __out,
_BiderctionalIterator __first, _BiderctionalIterator __last, 
const basic_regex<_CharT, _Traits>& __e, const _CharT* __fmt,
regex_constants::match_flag_type __flags = regex::constants::match_default)"</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>