This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug other/51711] New: regex.h contains incorrect code
- From: "ryanmolden at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 30 Dec 2011 06:08:17 +0000
- Subject: [Bug other/51711] New: regex.h contains incorrect code
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51711
Bug #: 51711
Summary: regex.h contains incorrect code
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: other
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: ryanmolden@gmail.com
The code in regex_replace looks like this
template <typename _Rx_traits, typename _Ch_type>
inline basic_string<_Ch_type>
regex_replace(const basic_string<_Ch_type>& __s,
const basic_regex<_Ch_type, _Rx_traits>& __e,
const basic_string<_Ch_type>& __fmt,
regex_constants::match_flag_type __flags,
= regex_constants::match_default)
{
std::string __result;
regex_replace(std::back_inserter(__result),
__s.begin(), __s.end(), __e, __fmt, __flags);
return __result;
}
However, the std::string is incorrect if you are attempting to use wstring and
wregex here (which should be allowed by all the other code which goes to pains
to use basic_string<_Ch_type>).
This code repros the bug:
#include <regex>
#include <string>
int main(int argc, char **argv)
{
std::wstring toProcess(L"Bug\r\n");
std::wstring result = std::regex_replace(toProcess, std::wregex(L"\\r"),
std::wstring(L"\\r"));
return 0;
}
compiled with:
g++ <filename> -std=c++0x +Wall
In file included from /usr/include/c++/4.6/regex:62:0,
from Test.cpp:1:
/usr/include/c++/4.6/bits/regex.h: In function std::basic_string<_Ch_type>
std::regex_replace(const std::basic_string<_Ch_type>&, const
std::basic_regex<_Ch_type, _Rx_traits>&, const std::basic_string<_Ch_type>&,
std::regex_constants::match_flag_type) [with _Rx_traits =
std::regex_traits<wchar_t>, _Ch_type = wchar_t,
std::regex_constants::match_flag_type = std::bitset<11ul>]:
Test.cpp:7:96: instantiated from here
/usr/include/c++/4.6/bits/regex.h:2225:14: error: could not convert __result
from std::string {aka std::basic_string<char>} to std::basic_string<wchar_t>
on Ubuntu 11.10 Server 64 bit edition with GCC 4.6.1