GSL/tests/pointers_tests.cpp
Werner Henze fcd55ee924
Some checks failed
CI_Android / Android (push) Has been cancelled
cmake_find_package / Build ${{ matrix.os }} (macos-latest) (push) Has been cancelled
cmake_find_package / Build ${{ matrix.os }} (ubuntu-latest) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 14, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 14, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 14, 12) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 17, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 17, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 17, 12) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 20, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 20, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Debug, 23, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 14, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 14, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 14, 12) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 17, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 17, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 17, 12) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 20, 10) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 20, 11) (push) Has been cancelled
Compiler Integration Tests / gcc (Release, 23, 11) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 13, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 13, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 13, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 13, 23) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 14, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 14, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 14, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 14, 23) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 15, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 15, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 15, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Debug, 15, 23) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 13, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 13, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 13, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 13, 23) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 14, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 14, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 14, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 14, 23) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 15, 14) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 15, 17) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 15, 20) (push) Has been cancelled
Compiler Integration Tests / clang (Release, 15, 23) (push) Has been cancelled
Compiler Integration Tests / xcode (Debug, 14, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Debug, 17, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Debug, 20, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Debug, 23, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Release, 14, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Release, 17, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Release, 20, 15.4) (push) Has been cancelled
Compiler Integration Tests / xcode (Release, 23, 15.4) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 14, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 14, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 14, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 14, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 17, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 17, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 17, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 17, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 20, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 20, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 20, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 20, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 23, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Debug, 23, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 14, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 14, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 14, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 14, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 17, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 17, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 17, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 17, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 20, , Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 20, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 20, -T ClangCL, Visual Studio 16 2019, windows-2019) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 20, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 23, , Visual Studio 17 2022, windows-2022) (push) Has been cancelled
Compiler Integration Tests / VisualStudio (Release, 23, -T ClangCL, Visual Studio 17 2022, windows-2022) (push) Has been cancelled
CI_iOS / iOS (push) Has been cancelled
Better use of std::enable_if (#1177)
* this commits adds tests that should fail, but don't

* Better use of std::enable_if

Replace the occurances of `class = std::enable_if_t<Cond>` and `typename = std::enable_if_t<Cond>` that have been identified in the previous commit with `std::enable_if_t<Cond, bool> = true`.

This commit is inspired by #1174, which changed one occurance in the owner header. This commit is aimed to fix all remaining occurances.

* fix failing checks

- core.cxx_gsl aktualisiert auf [](https://gitlab.avm.de/fos/repos/core.cxx_gsl/-/commit/)
- plc.access_lib aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.access_lib/-/commit/)
- plc.common aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.common/-/commit/)
- plc.daemon aktualisiert auf [](https://gitlab.avm.de/fos/repos/plc.daemon/-/commit/)
-

Test Plan:
-

---------

Co-authored-by: Werner Henze <werner.henze+gitcommits@posteo.de>
Co-authored-by: Werner Henze <w.henze@avm.de>
2024-12-23 10:40:22 -06:00

63 lines
2.0 KiB
C++

#include <gtest/gtest.h>
#include <gsl/pointers>
#include <memory>
#include <type_traits>
#include <utility>
namespace
{
// Custom pointer type that can be used for gsl::not_null, but for which these cannot be swapped.
struct NotMoveAssignableCustomPtr
{
NotMoveAssignableCustomPtr() = default;
NotMoveAssignableCustomPtr(const NotMoveAssignableCustomPtr&) = default;
NotMoveAssignableCustomPtr& operator=(const NotMoveAssignableCustomPtr&) = default;
NotMoveAssignableCustomPtr(NotMoveAssignableCustomPtr&&) = default;
NotMoveAssignableCustomPtr& operator=(NotMoveAssignableCustomPtr&&) = delete;
bool operator!=(std::nullptr_t) const { return true; }
int dummy{}; // Without this clang warns, that NotMoveAssignableCustomPtr() is unneeded
};
TEST(pointers_test, swap)
{
// taken from gh-1129:
gsl::not_null<std::unique_ptr<int>> a(std::make_unique<int>(0));
gsl::not_null<std::unique_ptr<int>> b(std::make_unique<int>(1));
EXPECT_TRUE(*a == 0);
EXPECT_TRUE(*b == 1);
gsl::swap(a, b);
EXPECT_TRUE(*a == 1);
EXPECT_TRUE(*b == 0);
// Make sure our custom ptr can be used with not_null. The shared_pr is to prevent "unused"
// compiler warnings.
const auto shared_custom_ptr{std::make_shared<NotMoveAssignableCustomPtr>()};
gsl::not_null<NotMoveAssignableCustomPtr> c{*shared_custom_ptr};
EXPECT_TRUE(c.get() != nullptr);
}
#if __cplusplus >= 201703l
using std::void_t;
#else // __cplusplus >= 201703l
template <class...>
using void_t = void;
#endif // __cplusplus < 201703l
template <typename U, typename = void>
static constexpr bool SwapCompilesFor = false;
template <typename U>
static constexpr bool
SwapCompilesFor<U, void_t<decltype(gsl::swap<U>(std::declval<gsl::not_null<U>&>(),
std::declval<gsl::not_null<U>&>()))>> = true;
static_assert(!SwapCompilesFor<NotMoveAssignableCustomPtr>,
"!SwapCompilesFor<NotMoveAssignableCustomPtr>");
} // namespace