Issue |
123309
|
Summary |
`basic_regex::assign` resets locale -> `imbue` has no effect
|
Labels |
|
Assignees |
|
Reporter |
Flamefire
|
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":
https://github.com/llvm/llvm-project/blob/320c2ee6c253f1bc0afe9c3d96cefb39195608f7/libcxx/include/regex#L2399
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
}
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs