mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
Upgrade to C++20 (#4239)
* Use explicit this capture required by C++20 * Use C++20 span * Replace wpi::numbers with std::numbers * Fix C++20 clang-tidy warning false positive in fmt * Remove ciso646 include since C++20 removed that header * Fix global-buffer-overflow asan warnings in ntcore tests * Add DIOSetProxy constructor to HAL * Upgrade MSVC compiler to 2022 * Bump native-utils to 2023.2.7 (changes to std=c++20) Co-authored-by: Peter Johnson <johnson.peter@gmail.com>
This commit is contained in:
@@ -8,23 +8,22 @@
|
||||
#include <initializer_list>
|
||||
#include <memory>
|
||||
#include <ostream>
|
||||
#include <span>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "TestPrinters.h"
|
||||
#include "gmock/gmock.h"
|
||||
|
||||
namespace wpi {
|
||||
|
||||
template <typename T>
|
||||
class SpanMatcher : public ::testing::MatcherInterface<span<T>> {
|
||||
class SpanMatcher : public ::testing::MatcherInterface<std::span<T>> {
|
||||
public:
|
||||
explicit SpanMatcher(span<T> good_) : good{good_.begin(), good_.end()} {}
|
||||
explicit SpanMatcher(std::span<T> good_) : good{good_.begin(), good_.end()} {}
|
||||
|
||||
bool MatchAndExplain(span<T> val,
|
||||
bool MatchAndExplain(std::span<T> val,
|
||||
::testing::MatchResultListener* listener) const override;
|
||||
void DescribeTo(::std::ostream* os) const override;
|
||||
void DescribeNegationTo(::std::ostream* os) const override;
|
||||
@@ -34,12 +33,12 @@ class SpanMatcher : public ::testing::MatcherInterface<span<T>> {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline ::testing::Matcher<span<const T>> SpanEq(span<const T> good) {
|
||||
inline ::testing::Matcher<std::span<const T>> SpanEq(std::span<const T> good) {
|
||||
return ::testing::MakeMatcher(new SpanMatcher(good));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline ::testing::Matcher<span<const T>> SpanEq(
|
||||
inline ::testing::Matcher<std::span<const T>> SpanEq(
|
||||
std::initializer_list<const T> good) {
|
||||
return ::testing::MakeMatcher(
|
||||
new SpanMatcher<const T>({good.begin(), good.end()}));
|
||||
@@ -47,7 +46,7 @@ inline ::testing::Matcher<span<const T>> SpanEq(
|
||||
|
||||
template <typename T>
|
||||
bool SpanMatcher<T>::MatchAndExplain(
|
||||
span<T> val, ::testing::MatchResultListener* listener) const {
|
||||
std::span<T> val, ::testing::MatchResultListener* listener) const {
|
||||
if (val.size() != good.size() ||
|
||||
!std::equal(val.begin(), val.end(), good.begin())) {
|
||||
return false;
|
||||
@@ -57,17 +56,17 @@ bool SpanMatcher<T>::MatchAndExplain(
|
||||
|
||||
template <typename T>
|
||||
void SpanMatcher<T>::DescribeTo(::std::ostream* os) const {
|
||||
PrintTo(span<T>{good}, os);
|
||||
PrintTo(std::span<T>{good}, os);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void SpanMatcher<T>::DescribeNegationTo(::std::ostream* os) const {
|
||||
*os << "is not equal to ";
|
||||
PrintTo(span<T>{good}, os);
|
||||
PrintTo(std::span<T>{good}, os);
|
||||
}
|
||||
|
||||
} // namespace wpi
|
||||
|
||||
inline wpi::span<const uint8_t> operator"" _us(const char* str, size_t len) {
|
||||
inline std::span<const uint8_t> operator"" _us(const char* str, size_t len) {
|
||||
return {reinterpret_cast<const uint8_t*>(str), len};
|
||||
}
|
||||
|
||||
@@ -5,11 +5,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <ostream>
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace wpi {
|
||||
@@ -21,7 +20,7 @@ inline void PrintTo(std::string_view str, ::std::ostream* os) {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void PrintTo(span<T> val, ::std::ostream* os) {
|
||||
void PrintTo(std::span<T> val, ::std::ostream* os) {
|
||||
*os << '{';
|
||||
bool first = true;
|
||||
for (auto v : val) {
|
||||
|
||||
@@ -12,15 +12,15 @@
|
||||
|
||||
using namespace std::string_view_literals;
|
||||
|
||||
namespace wpi {
|
||||
namespace std { // NOLINT (clang-tidy.cert-dcl58-cpp)
|
||||
template <typename T, typename U>
|
||||
inline bool operator==(span<T> lhs, span<U> rhs) {
|
||||
inline bool operator==(std::span<T> lhs, std::span<U> rhs) {
|
||||
if (lhs.size() != rhs.size()) {
|
||||
return false;
|
||||
}
|
||||
return std::equal(lhs.begin(), lhs.end(), rhs.begin());
|
||||
}
|
||||
} // namespace wpi
|
||||
} // namespace std
|
||||
|
||||
namespace nt {
|
||||
|
||||
@@ -102,25 +102,25 @@ TEST_F(ValueTest, Raw) {
|
||||
std::vector<uint8_t> arr{5, 4, 3, 2, 1};
|
||||
auto v = Value::MakeRaw(arr);
|
||||
ASSERT_EQ(NT_RAW, v.type());
|
||||
ASSERT_EQ(wpi::span<const uint8_t>(arr), v.GetRaw());
|
||||
ASSERT_EQ(std::span<const uint8_t>(arr), v.GetRaw());
|
||||
NT_Value cv;
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_RAW, cv.type);
|
||||
ASSERT_EQ(5u, cv.data.v_raw.size);
|
||||
ASSERT_EQ(wpi::span(reinterpret_cast<const uint8_t*>("\5\4\3\2\1"), 5),
|
||||
wpi::span(cv.data.v_raw.data, 5));
|
||||
ASSERT_EQ(std::span(reinterpret_cast<const uint8_t*>("\5\4\3\2\1"), 5),
|
||||
std::span(cv.data.v_raw.data, 5));
|
||||
|
||||
std::vector<uint8_t> arr2{1, 2, 3, 4, 5, 6};
|
||||
v = Value::MakeRaw(arr2);
|
||||
ASSERT_EQ(NT_RAW, v.type());
|
||||
ASSERT_EQ(wpi::span<const uint8_t>(arr2), v.GetRaw());
|
||||
ASSERT_EQ(std::span<const uint8_t>(arr2), v.GetRaw());
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_RAW, cv.type);
|
||||
ASSERT_EQ(6u, cv.data.v_raw.size);
|
||||
ASSERT_EQ(wpi::span(reinterpret_cast<const uint8_t*>("\1\2\3\4\5\6"), 6),
|
||||
wpi::span(cv.data.v_raw.data, 6));
|
||||
ASSERT_EQ(std::span(reinterpret_cast<const uint8_t*>("\1\2\3\4\5\6"), 6),
|
||||
std::span(cv.data.v_raw.data, 6));
|
||||
|
||||
NT_DisposeValue(&cv);
|
||||
}
|
||||
@@ -129,7 +129,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
std::vector<int> vec{1, 0, 1};
|
||||
auto v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v.GetBooleanArray());
|
||||
ASSERT_EQ(std::span<const int>(vec), v.GetBooleanArray());
|
||||
NT_Value cv;
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
@@ -143,7 +143,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
vec = {0, 1, 0};
|
||||
v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v.GetBooleanArray());
|
||||
ASSERT_EQ(std::span<const int>(vec), v.GetBooleanArray());
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, cv.type);
|
||||
@@ -156,7 +156,7 @@ TEST_F(ValueTest, BooleanArray) {
|
||||
vec = {1, 0};
|
||||
v = Value::MakeBooleanArray(vec);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const int>(vec), v.GetBooleanArray());
|
||||
ASSERT_EQ(std::span<const int>(vec), v.GetBooleanArray());
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_BOOLEAN_ARRAY, cv.type);
|
||||
@@ -171,7 +171,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
std::vector<double> vec{0.5, 0.25, 0.5};
|
||||
auto v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v.GetDoubleArray());
|
||||
ASSERT_EQ(std::span<const double>(vec), v.GetDoubleArray());
|
||||
NT_Value cv;
|
||||
NT_InitValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
@@ -185,7 +185,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
vec = {0.25, 0.5, 0.25};
|
||||
v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v.GetDoubleArray());
|
||||
ASSERT_EQ(std::span<const double>(vec), v.GetDoubleArray());
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, cv.type);
|
||||
@@ -198,7 +198,7 @@ TEST_F(ValueTest, DoubleArray) {
|
||||
vec = {0.5, 0.25};
|
||||
v = Value::MakeDoubleArray(vec);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, v.type());
|
||||
ASSERT_EQ(wpi::span<const double>(vec), v.GetDoubleArray());
|
||||
ASSERT_EQ(std::span<const double>(vec), v.GetDoubleArray());
|
||||
NT_DisposeValue(&cv);
|
||||
ConvertToC(v, &cv);
|
||||
ASSERT_EQ(NT_DOUBLE_ARRAY, cv.type);
|
||||
|
||||
@@ -36,7 +36,7 @@ class MockNetworkStartupInterface : public NetworkStartupInterface {
|
||||
const wpi::json& properties, const PubSubOptions& options),
|
||||
(override));
|
||||
MOCK_METHOD(void, Subscribe,
|
||||
(NT_Subscriber subHandle, wpi::span<const std::string> prefixes,
|
||||
(NT_Subscriber subHandle, std::span<const std::string> prefixes,
|
||||
const PubSubOptions& options),
|
||||
(override));
|
||||
MOCK_METHOD(void, SetValue, (NT_Publisher pubHandle, const Value& value),
|
||||
@@ -57,7 +57,7 @@ class MockNetworkInterface : public NetworkInterface {
|
||||
const wpi::json& update),
|
||||
(override));
|
||||
MOCK_METHOD(void, Subscribe,
|
||||
(NT_Subscriber subHandle, wpi::span<const std::string> prefixes,
|
||||
(NT_Subscriber subHandle, std::span<const std::string> prefixes,
|
||||
const PubSubOptions& options),
|
||||
(override));
|
||||
MOCK_METHOD(void, Unsubscribe, (NT_Subscriber subHandle), (override));
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "net/WireConnection.h"
|
||||
@@ -28,7 +28,7 @@ class MockWireConnection : public WireConnection {
|
||||
BinaryWriter SendBinary() override { return {m_binary_os, *this}; }
|
||||
|
||||
MOCK_METHOD(void, Text, (std::string_view contents));
|
||||
MOCK_METHOD(void, Binary, (wpi::span<const uint8_t> contents));
|
||||
MOCK_METHOD(void, Binary, (std::span<const uint8_t> contents));
|
||||
|
||||
MOCK_METHOD(void, Flush, (), (override));
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ class MockClientMessageHandler : public net::ClientMessageHandler {
|
||||
MOCK_METHOD2(ClientSetProperties,
|
||||
void(std::string_view name, const wpi::json& update));
|
||||
MOCK_METHOD3(ClientSubscribe,
|
||||
void(int64_t subuid, wpi::span<const std::string> prefixes,
|
||||
void(int64_t subuid, std::span<const std::string> prefixes,
|
||||
const PubSubOptions& options));
|
||||
MOCK_METHOD1(ClientUnsubscribe, void(int64_t subuid));
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <span>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
@@ -65,7 +66,7 @@ TEST_F(WireEncoderTextTest, SetProperties) {
|
||||
}
|
||||
|
||||
TEST_F(WireEncoderTextTest, Subscribe) {
|
||||
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
|
||||
net::WireEncodeSubscribe(os, 5, std::span<const std::string_view>{{"a", "b"}},
|
||||
PubSubOptions{});
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"subscribe\",\"params\":{"
|
||||
@@ -75,7 +76,7 @@ TEST_F(WireEncoderTextTest, Subscribe) {
|
||||
TEST_F(WireEncoderTextTest, SubscribeSendAll) {
|
||||
PubSubOptions options;
|
||||
options.sendAll = true;
|
||||
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
|
||||
net::WireEncodeSubscribe(os, 5, std::span<const std::string_view>{{"a", "b"}},
|
||||
options);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"subscribe\",\"params\":{"
|
||||
@@ -86,7 +87,7 @@ TEST_F(WireEncoderTextTest, SubscribeSendAll) {
|
||||
TEST_F(WireEncoderTextTest, SubscribePeriodic) {
|
||||
PubSubOptions options;
|
||||
options.periodic = 0.5;
|
||||
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
|
||||
net::WireEncodeSubscribe(os, 5, std::span<const std::string_view>{{"a", "b"}},
|
||||
options);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"subscribe\",\"params\":{"
|
||||
@@ -98,7 +99,7 @@ TEST_F(WireEncoderTextTest, SubscribeAllOptions) {
|
||||
PubSubOptions options;
|
||||
options.sendAll = true;
|
||||
options.periodic = 0.5;
|
||||
net::WireEncodeSubscribe(os, 5, std::vector<std::string_view>{{"a", "b"}},
|
||||
net::WireEncodeSubscribe(os, 5, std::span<const std::string_view>{{"a", "b"}},
|
||||
options);
|
||||
ASSERT_EQ(os.str(),
|
||||
"{\"method\":\"subscribe\",\"params\":{"
|
||||
|
||||
@@ -6,10 +6,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <span>
|
||||
#include <vector>
|
||||
|
||||
#include <wpi/raw_ostream.h>
|
||||
#include <wpi/span.h>
|
||||
|
||||
#include "gmock/gmock.h"
|
||||
#include "net3/WireConnection3.h"
|
||||
@@ -24,7 +24,7 @@ class MockWireConnection3 : public WireConnection3 {
|
||||
|
||||
Writer Send() override { return {m_os, *this}; }
|
||||
|
||||
MOCK_METHOD(void, Data, (wpi::span<const uint8_t> data));
|
||||
MOCK_METHOD(void, Data, (std::span<const uint8_t> data));
|
||||
|
||||
MOCK_METHOD(void, Flush, (), (override));
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ class MockMessageHandler3 : public net3::MessageHandler3 {
|
||||
MOCK_METHOD2(FlagsUpdate, void(unsigned int id, unsigned int flags));
|
||||
MOCK_METHOD1(EntryDelete, void(unsigned int id));
|
||||
MOCK_METHOD3(ExecuteRpc, void(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> params));
|
||||
std::span<const uint8_t> params));
|
||||
MOCK_METHOD3(RpcResponse, void(unsigned int id, unsigned int uid,
|
||||
wpi::span<const uint8_t> result));
|
||||
std::span<const uint8_t> result));
|
||||
};
|
||||
|
||||
class WireDecoder3Test : public ::testing::Test {
|
||||
@@ -52,7 +52,7 @@ class WireDecoder3Test : public ::testing::Test {
|
||||
StrictMock<MockMessageHandler3> handler;
|
||||
net3::WireDecoder3 decoder{handler};
|
||||
|
||||
void DecodeComplete(wpi::span<const uint8_t> in) {
|
||||
void DecodeComplete(std::span<const uint8_t> in) {
|
||||
decoder.Execute(&in);
|
||||
EXPECT_TRUE(in.empty());
|
||||
ASSERT_EQ(decoder.GetError(), "");
|
||||
|
||||
Reference in New Issue
Block a user