From fa27294f32e9c8683592ba3b924025123fe510d2 Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Thu, 1 Dec 2022 17:12:24 +0800 Subject: [PATCH 1/2] Assert that comparisons between `locale` are noexcept --- tests/std/tests/Dev09_056375_locale_cleanup/test.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/std/tests/Dev09_056375_locale_cleanup/test.cpp b/tests/std/tests/Dev09_056375_locale_cleanup/test.cpp index ce23d39c16c..11a5f969769 100644 --- a/tests/std/tests/Dev09_056375_locale_cleanup/test.cpp +++ b/tests/std/tests/Dev09_056375_locale_cleanup/test.cpp @@ -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 From e56cf68d729076fb81cd28534fd64c090307a82c Mon Sep 17 00:00:00 2001 From: "A. Jiang" Date: Thu, 1 Dec 2022 17:18:05 +0800 Subject: [PATCH 2/2] Avoid allocation when comparing `locale`s --- stl/inc/xlocale | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stl/inc/xlocale b/stl/inc/xlocale index 874f94288da..2a96cec62ac 100644 --- a/stl/inc/xlocale +++ b/stl/inc/xlocale @@ -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