<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/123309>123309</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`basic_regex::assign` resets locale -> `imbue` has no effect
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Flamefire
</td>
</tr>
</table>
<pre>
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
}
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUVMGO4zYM_RrlQmygUElsH3zw7ozRQ0_t9ryQZNpWoUhZSc7M_H0hW8HMdHfQLRAgsiiSj4-PlDGayRG17PSZnR52ckmzD21v5YVGE2in_PDSdhGuFCDNBDFJN8gwgAR25kpGo78FmuiZiY6JzlzUQuzMQUtrIVCkFIufDzTAVaZEwQHD2uxpDwzx60wQaFqsDEDP10AxGu9g8BTB-QQXmfQM0r2AnmWQOlGASN8XcppAjqkAywn3DJFhw3jHePfb9mBDknyGu1Wb4fnNabu4kEvgrxRk8gFMhEDfF5Phdv3Xxz-y572ufYntn-hWEj_Jl_exTQRzuVrKYWkAk97yYL2WljKe_DVZr6S9X8oIGSu5AZbritu4aX3nbxSslwNo72IKi07ZIsHRE6zsg3RDqSZbTForRkyziZkUkVHPKV1jPmLPsJ9Mmhe11_7CsLf2dv_7dA3-b9KJYa-sVwx7gVwj0VnjSYwHpbkcqdFiaM6aRiWaQ3M683qscgCj9PMzw944bZeBGPabOlD8jqJ515o0U6DMlvMricnnDruJ3hBV-P5TZkJB-4G2UtiZlx_vGIqSDZj4svkx8fiDpcj0R4OWMVJIxcQ74xIkiunbRRqXleoSrJx1Mkya4Ubgl1WP61f3ar7dzWup1WfGOwCAmIZtQO6tZlivYl31Kj56poCJh3_fbmdtc7v1GufjCNt5kxnDWv787SahUCyFDazDfqJkfcmRoWQ072JsUoIvpW8e1KrEGwUzvpQ0b-JtY4S1-ijefyVX7x6HlR6GWNbKqvRfqaGEucPvTaD4awDke8-_HD1fSec5j4vWFOPa9oe3Et0NrRga0cgdtYdKVAd-Rqx3c3vgtTrow4nGE2rRYCWOsua8Og6nSvOadqZFjid-OFS8ERzrfV3Vx3Mla4X1UY9KsSOnizR2nwd378O0MzEu1B5QCN7srFRk4323h3Ydb7VMkR25NTHFV79kkqX2Zyv9dbGVNVa0-YmJx7erEWa5jjKNI-m0W4Jt__fCWdFHhn0p4NbiPwEAAP__KjgE2w">