From a44260b8b4ee2382394675330e5a6da3f74daf3e Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Tue, 24 Sep 2024 14:01:57 +1000 Subject: [PATCH] fixed_string: add constexpr equality operators This fixes some errors seen under UBSan when comparing fixed_string objects in std::integral_constant under GCC. In particular the M != N case appears to be important. --- cruft/util/fixed_string.hpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cruft/util/fixed_string.hpp b/cruft/util/fixed_string.hpp index 18122a23..4f5a007d 100644 --- a/cruft/util/fixed_string.hpp +++ b/cruft/util/fixed_string.hpp @@ -43,9 +43,18 @@ namespace cruft { auto begin (void) const& noexcept { return std::begin (value); } auto end (void) const& noexcept { return std::end (value); } - }; + constexpr bool + operator== (fixed_string const&) const noexcept = default; + + template + requires (M != N) + constexpr bool + operator== (fixed_string const&) const noexcept + { return false; } + }; + template fixed_string (char const (&)[N]) -> fixed_string; }