Open
Description
As per the standard a basic_regex::imbue
call resets the stored pattern (i.e. "The regular expression does not match any character sequence after the call.")
Hence a call to assign
or the assignment operator is required AFTER imbue
.
However the way assign
is implemented it resets the locale to the global locale as all end up calling the overload constructing a new regex and assigning it to "this":
llvm-project/libcxx/include/regex
Line 2399 in 320c2ee
Hence there is no way to change the locale.
Sample code:
#include <locale>
#include <regex>
#include <cassert>
int test_main(int /*argc*/, char** /*argv*/)
{
std::locale a("");
std::locale b = std::locale::classic();
std::locale::global(a);
std::regex r;
assert(r.getloc() == a);
// Change to b and verify
assert(r.imbue(b) == a);
assert(r.getloc() == b);
r = "pattern";
assert(r.getloc() == b); // Fires
assert(r.getloc() == a); // Unexpected success
}