Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

<xlocale>: Avoid allocation when comparing two locale values #3250

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions stl/inc/xlocale
Original file line number Diff line number Diff line change
Expand Up @@ -380,12 +380,12 @@ public:
return nullptr; // no entry in current locale
}

_NODISCARD bool operator==(const locale& _Loc) const { // compare locales for equality
return _Ptr == _Loc._Ptr || (name().compare("*") != 0 && name().compare(_Loc.name()) == 0);
_NODISCARD bool operator==(const locale& _Loc) const noexcept /* strengthened */ { // compare locales for equality
return _Ptr == _Loc._Ptr || (_CSTD strcmp(_C_str(), "*") != 0 && _CSTD strcmp(_C_str(), _Loc._C_str()) == 0);
}

#if !_HAS_CXX20
_NODISCARD bool operator!=(const locale& _Right) const {
_NODISCARD bool operator!=(const locale& _Right) const noexcept /* strengthened */ {
return !(*this == _Right);
}
#endif // !_HAS_CXX20
Expand Down
3 changes: 3 additions & 0 deletions tests/std/tests/Dev09_056375_locale_cleanup/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ using namespace std;

#define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)

STATIC_ASSERT(noexcept(locale{} == locale{}));
STATIC_ASSERT(noexcept(locale{} != locale{}));

void test_dll() {
puts("Calling dll");
#ifdef _M_CEE
Expand Down