From 1cbc7bc0f16ed7aa1f3353f9138338cf1cd5a196 Mon Sep 17 00:00:00 2001 From: Laurynas Biveinis Date: Fri, 14 Feb 2025 07:05:03 +0200 Subject: [PATCH] Replace the two-way comparison operators in qsbr_ptr with the three-way one Add a workaround for clang 11 (only that version) spurious warning --- .circleci/config.yml | 2 +- CMakeLists.txt | 6 ++++++ qsbr_ptr.hpp | 25 ++++--------------------- test/test_qsbr_ptr.cpp | 1 + 4 files changed, 12 insertions(+), 22 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 78f9d8bf..4597b95b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -152,7 +152,7 @@ jobs: - run: name: Build working_directory: build - command: make -j2 -k + command: make -k - run: name: Correctness test working_directory: build diff --git a/CMakeLists.txt b/CMakeLists.txt index ad134fe3..d6713367 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,9 @@ set(CLANG_CXX_WARNING_FLAGS "-Wunused-macros" "-Wunused-member-function" "-Wunused-template" "-Wused-but-marked-unused" "-Wvector-conversion" "-Wvla" "-Wweak-template-vtables" "-Wweak-vtables" "-Wzero-as-null-pointer-constant") +# Workaround https://github.com/llvm/llvm-project/issues/43670 - a spurious +# warning with the spaceship operator +set(CLANG_11_CXX_WARNING_FLAGS "-Wno-zero-as-null-pointer-constant") set(CLANG_LT_13_CXX_WARNING_FLAGS "-Wreserved-id-macro") set(CLANG_GE_13_CXX_WARNING_FLAGS "-Wreserved-identifier") @@ -400,6 +403,8 @@ set(cxx_ge_12 "$,12.0>") set(cxx_lt_13 "$,13.0>") set(cxx_ge_13 "$,13.0>") set(cxx_ge_14 "$,14.0>") +set(cxx_lt_12 "$,12.0>") +set(is_clang11_not_windows "$") set(is_clang_lt_13_not_windows "$") set(is_clang_ge_13_not_windows "$") set(is_clang_ge_14_not_windows "$") @@ -705,6 +710,7 @@ function(COMMON_TARGET_PROPERTIES TARGET) "$<$:${MSVC_CXX_WARNING_FLAGS}>" "$<$:${MSVC_CLANG_WARNING_FLAGS}>" "$<$:${CLANG_CXX_WARNING_FLAGS}>" + "$<$:${CLANG_11_CXX_WARNING_FLAGS}>" "$<$:${CLANG_LT_13_CXX_WARNING_FLAGS}>" "$<$:${CLANG_GE_13_CXX_WARNING_FLAGS}>" "$<$:${GCC_CXX_WARNING_FLAGS}>" diff --git a/qsbr_ptr.hpp b/qsbr_ptr.hpp index 607fa8e0..af15aca5 100644 --- a/qsbr_ptr.hpp +++ b/qsbr_ptr.hpp @@ -15,6 +15,7 @@ // IWYU pragma: no_include <__cstddef/byte.h> +#include // IWYU pragma: keep #include #include #include @@ -257,28 +258,10 @@ class [[nodiscard]] qsbr_ptr : public detail::qsbr_ptr_base { return get() == other.get(); } - /// Compare less than or equal to \a other. - [[nodiscard, gnu::pure]] constexpr bool operator<=( + /// Three-way compare to \a other. + [[nodiscard, gnu::pure]] constexpr auto operator<=>( qsbr_ptr other) const noexcept { - return get() <= other.get(); - } - - /// Compare greater than or equal to \a other. - [[nodiscard, gnu::pure]] constexpr bool operator>=( - qsbr_ptr other) const noexcept { - return get() >= other.get(); - } - - /// Compare less than \a other. - [[nodiscard, gnu::pure]] constexpr bool operator<( - qsbr_ptr other) const noexcept { - return get() < other.get(); - } - - /// Compare greater than \a other. - [[nodiscard, gnu::pure]] constexpr bool operator>( - qsbr_ptr other) const noexcept { - return get() > other.get(); + return get() <=> other.get(); } /// Get the raw pointer. diff --git a/test/test_qsbr_ptr.cpp b/test/test_qsbr_ptr.cpp index aeb6e10b..f5c2c7d0 100644 --- a/test/test_qsbr_ptr.cpp +++ b/test/test_qsbr_ptr.cpp @@ -8,6 +8,7 @@ #include #include +#include // IWYU pragma: keep #include #include #include