-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Open
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regexIssues related to regex
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
| return assign(basic_regex(__first, __last, __f)); |
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
}
Metadata
Metadata
Assignees
Labels
libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.regexIssues related to regexIssues related to regex