Skip to content

Commit 321a9a3

Browse files
author
Werner Henze
committed
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: -
1 parent 0dc891b commit 321a9a3

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

tests/byte_tests.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,40 +131,46 @@ TEST(byte_tests, aliasing)
131131
EXPECT_TRUE(res == i);
132132
}
133133

134-
// These are regressions, should be fixed.
134+
#if __cplusplus >= 201703l
135+
using std::void_t;
136+
#else // __cplusplus >= 201703l
137+
template <class...>
138+
using void_t = void;
139+
#endif // __cplusplus < 201703l
140+
135141
template <typename U, typename = void>
136142
static constexpr bool LShiftCompilesFor = false;
137143
template <typename U>
138144
static constexpr bool LShiftCompilesFor<
139-
U, std::void_t<decltype(gsl::operator<< <float>(declval<gsl::byte>(), declval<U>()))>> = true;
145+
U, void_t<decltype(gsl::operator<< <float>(declval<gsl::byte>(), declval<U>()))>> = true;
140146
static_assert(!LShiftCompilesFor<float>, "!LShiftCompilesFor<float>");
141147

142148
template <typename U, typename = void>
143149
static constexpr bool RShiftCompilesFor = false;
144150
template <typename U>
145151
static constexpr bool RShiftCompilesFor<
146-
U, std::void_t<decltype(gsl::operator>> <U>(declval<gsl::byte>(), declval<U>()))>> = true;
152+
U, void_t<decltype(gsl::operator>> <U>(declval<gsl::byte>(), declval<U>()))>> = true;
147153
static_assert(!RShiftCompilesFor<float>, "!RShiftCompilesFor<float>");
148154

149155
template <typename U, typename = void>
150156
static constexpr bool LShiftAssignCompilesFor = false;
151157
template <typename U>
152158
static constexpr bool LShiftAssignCompilesFor<
153-
U, std::void_t<decltype(gsl::operator<<= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
159+
U, void_t<decltype(gsl::operator<<= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
154160
static_assert(!LShiftAssignCompilesFor<float>, "!LShiftAssignCompilesFor<float>");
155161

156162
template <typename U, typename = void>
157163
static constexpr bool RShiftAssignCompilesFor = false;
158164
template <typename U>
159165
static constexpr bool RShiftAssignCompilesFor<
160-
U, std::void_t<decltype(gsl::operator>>= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
166+
U, void_t<decltype(gsl::operator>>= <U>(declval<gsl::byte&>(), declval<U>()))>> = true;
161167
static_assert(!RShiftAssignCompilesFor<float>, "!RShiftAssignCompilesFor<float>");
162168

163169
template <typename U, typename = void>
164170
static constexpr bool ToIntegerCompilesFor = false;
165171
template <typename U>
166172
static constexpr bool
167-
ToIntegerCompilesFor<U, std::void_t<decltype(gsl::to_integer<U>(gsl::byte{}))>> = true;
173+
ToIntegerCompilesFor<U, void_t<decltype(gsl::to_integer<U>(gsl::byte{}))>> = true;
168174
static_assert(!ToIntegerCompilesFor<float>, "!ToIntegerCompilesFor<float>");
169175

170176
} // namespace

tests/pointers_tests.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88

99
namespace
1010
{
11+
// Custom pointer type that can be used for gsl::not_null, but for which these cannot be swapped.
12+
struct NotMoveAssignableCustomPtr
13+
{
14+
NotMoveAssignableCustomPtr() = default;
15+
NotMoveAssignableCustomPtr(const NotMoveAssignableCustomPtr&) = default;
16+
NotMoveAssignableCustomPtr& operator=(const NotMoveAssignableCustomPtr&) = default;
17+
NotMoveAssignableCustomPtr(NotMoveAssignableCustomPtr&&) = default;
18+
NotMoveAssignableCustomPtr& operator=(NotMoveAssignableCustomPtr&&) = delete;
19+
20+
bool operator!=(std::nullptr_t) const { return true; }
21+
22+
int dummy{}; // Without this clang warns, that NotMoveAssignableCustomPtr() is unneeded
23+
};
1124

1225
TEST(pointers_test, swap)
1326
{
@@ -22,21 +35,28 @@ TEST(pointers_test, swap)
2235

2336
EXPECT_TRUE(*a == 1);
2437
EXPECT_TRUE(*b == 0);
38+
39+
// Make sure our custom ptr can be used with not_null. The shared_pr is to prevent "unused"
40+
// compiler warnings.
41+
const auto shared_custom_ptr{std::make_shared<NotMoveAssignableCustomPtr>()};
42+
gsl::not_null<NotMoveAssignableCustomPtr> c{*shared_custom_ptr};
43+
EXPECT_TRUE(c.get() != nullptr);
2544
}
2645

27-
// These are regressions, should be fixed.
28-
struct NotMovable
29-
{
30-
NotMovable(NotMovable&&) = delete;
31-
NotMovable& operator=(NotMovable&&) = delete;
32-
};
46+
#if __cplusplus >= 201703l
47+
using std::void_t;
48+
#else // __cplusplus >= 201703l
49+
template <class...>
50+
using void_t = void;
51+
#endif // __cplusplus < 201703l
52+
3353
template <typename U, typename = void>
3454
static constexpr bool SwapCompilesFor = false;
3555
template <typename U>
3656
static constexpr bool
37-
SwapCompilesFor<U, std::void_t<decltype(gsl::swap<U>(std::declval<gsl::not_null<U>&>(),
38-
std::declval<gsl::not_null<U>&>()))>> =
39-
true;
40-
static_assert(!SwapCompilesFor<NotMovable>, "!SwapCompilesFor<NotMovable>");
57+
SwapCompilesFor<U, void_t<decltype(gsl::swap<U>(std::declval<gsl::not_null<U>&>(),
58+
std::declval<gsl::not_null<U>&>()))>> = true;
59+
static_assert(!SwapCompilesFor<NotMoveAssignableCustomPtr>,
60+
"!SwapCompilesFor<NotMoveAssignableCustomPtr>");
4161

4262
} // namespace

tests/span_compatibility_tests.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,12 +1005,18 @@ static_assert(std::is_convertible<const std::array<int, 3>&, gsl::span<const int
10051005
"std::is_convertible<const std::array<int, 3>&, gsl::span<const int>>");
10061006

10071007
#if __cplusplus >= 201703l
1008+
using std::void_t;
1009+
#else // __cplusplus >= 201703l
1010+
template <class...>
1011+
using void_t = void;
1012+
#endif // __cplusplus < 201703l
1013+
10081014
template <typename U, typename = void>
10091015
static constexpr bool AsWritableBytesCompilesFor = false;
10101016

10111017
template <typename U>
10121018
static constexpr bool
1013-
AsWritableBytesCompilesFor<U, void_t<decltype(as_writable_bytes(declval<U>()))>> = true;
1019+
AsWritableBytesCompilesFor<U, ::void_t<decltype(as_writable_bytes(declval<U>()))>> = true;
10141020

10151021
static_assert(AsWritableBytesCompilesFor<gsl::span<int>>,
10161022
"AsWritableBytesCompilesFor<gsl::span<int>>");
@@ -1020,4 +1026,3 @@ static_assert(!AsWritableBytesCompilesFor<gsl::span<const int>>,
10201026
"!AsWritableBytesCompilesFor<gsl::span<const int>>");
10211027
static_assert(!AsWritableBytesCompilesFor<gsl::span<const int, 9>>,
10221028
"!AsWritableBytesCompilesFor<gsl::span<const int, 9>>");
1023-
#endif // __cplusplus >= 201703l

0 commit comments

Comments
 (0)