Skip to content

Commit

Permalink
Upgrade to C++20 (wpilibsuite#4239)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
calcmogul and PeterJohnson authored Oct 15, 2022
1 parent 3961430 commit fbdc810
Show file tree
Hide file tree
Showing 355 changed files with 1,659 additions and 2,918 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ jobs:
fail-fast: false
matrix:
include:
- os: windows-2019
- os: windows-2022
artifact-name: Win64Debug
architecture: x64
task: "build"
build-options: "-PciDebugOnly --max-workers 1"
outputs: "build/allOutputs"
- os: windows-2019
- os: windows-2022
artifact-name: Win64Release
architecture: x64
build-options: "-PciReleaseOnly --max-workers 1"
Expand All @@ -69,7 +69,7 @@ jobs:
build-options: "-Pbuildalldesktop"
task: "build"
outputs: "build/allOutputs"
- os: windows-2019
- os: windows-2022
artifact-name: Win32
architecture: x86
task: ":ntcoreffi:build"
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ Using Gradle makes building WPILib very straightforward. It only has a few depen
- On Windows, install the JDK 11 .msi from the link above
- On macOS, install the JDK 11 .pkg from the link above
- C++ compiler
- On Linux, install GCC 8 or greater
- On Windows, install [Visual Studio Community 2022 or 2019](https://visualstudio.microsoft.com/vs/community/) and select the C++ programming language during installation (Gradle can't use the build tools for Visual Studio)
- On Linux, install GCC 11 or greater
- On Windows, install [Visual Studio Community 2022](https://visualstudio.microsoft.com/vs/community/) and select the C++ programming language during installation (Gradle can't use the build tools for Visual Studio)
- On macOS, install the Xcode command-line build tools via `xcode-select --install`
- ARM compiler toolchain
- Run `./gradlew installRoboRioToolchain` after cloning this repository
Expand Down
2 changes: 0 additions & 2 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ popper.js wpinet/src/main/native/resources/popper-*
units wpimath/src/main/native/include/units/
Eigen wpimath/src/main/native/thirdparty/eigen/include/
StackWalker wpiutil/src/main/native/windows/StackWalker.*
TCB span wpiutil/src/main/native/thirdparty/include/wpi/span.h
wpiutil/src/test/native/cpp/span/
GHC filesystem wpiutil/src/main/native/thirdparty/include/wpi/ghc/
Team 254 Library wpilibj/src/main/java/edu/wpi/first/wpilibj/spline/SplineParameterizer.java
wpilibj/src/main/java/edu/wpi/first/wpilibj/trajectory/TrajectoryParameterizer.java
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ repositories {
}
}
dependencies {
implementation "edu.wpi.first:native-utils:2023.2.4"
implementation "edu.wpi.first:native-utils:2023.2.7"
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ Instance::Instance() {

// Listener for video events
m_videoListener = cs::VideoListener{
[=](const cs::VideoEvent& event) {
[=, this](const cs::VideoEvent& event) {
std::scoped_lock lock(m_mutex);
CS_Status status = 0;
switch (event.kind) {
Expand Down Expand Up @@ -511,7 +511,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(const std::string& host) {
return AddAxisCamera("Axis Camera", host);
}

cs::AxisCamera CameraServer::AddAxisCamera(wpi::span<const std::string> hosts) {
cs::AxisCamera CameraServer::AddAxisCamera(std::span<const std::string> hosts) {
return AddAxisCamera("Axis Camera", hosts);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
}

cs::AxisCamera CameraServer::AddAxisCamera(std::string_view name,
wpi::span<const std::string> hosts) {
std::span<const std::string> hosts) {
cs::AxisCamera camera{name, hosts};
StartAutomaticCapture(camera);
auto csShared = GetCameraServerShared();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

#include <stdint.h>

#include <span>
#include <string>
#include <string_view>

#include <wpi/span.h>

#include "cscore.h"
#include "cscore_cv.h"

Expand Down Expand Up @@ -110,7 +109,7 @@ class CameraServer {
*
* @param hosts Array of Camera host IPs/DNS names
*/
static cs::AxisCamera AddAxisCamera(wpi::span<const std::string> hosts);
static cs::AxisCamera AddAxisCamera(std::span<const std::string> hosts);

/**
* Adds an Axis IP camera.
Expand Down Expand Up @@ -155,7 +154,7 @@ class CameraServer {
* @param hosts Array of Camera host IPs/DNS names
*/
static cs::AxisCamera AddAxisCamera(std::string_view name,
wpi::span<const std::string> hosts);
std::span<const std::string> hosts);

/**
* Adds an Axis IP camera.
Expand Down
2 changes: 1 addition & 1 deletion cscore/src/main/native/cpp/ConfigurableSourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int ConfigurableSourceImpl::CreateProperty(
}

void ConfigurableSourceImpl::SetEnumPropertyChoices(
int property, wpi::span<const std::string> choices, CS_Status* status) {
int property, std::span<const std::string> choices, CS_Status* status) {
std::scoped_lock lock(m_mutex);
auto prop = GetProperty(property);
if (!prop) {
Expand Down
5 changes: 2 additions & 3 deletions cscore/src/main/native/cpp/ConfigurableSourceImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
#include <atomic>
#include <functional>
#include <memory>
#include <span>
#include <string>
#include <string_view>
#include <vector>

#include <wpi/span.h>

#include "SourceImpl.h"

namespace cs {
Expand Down Expand Up @@ -42,7 +41,7 @@ class ConfigurableSourceImpl : public SourceImpl {
int maximum, int step, int defaultValue, int value,
std::function<void(CS_Property property)> onChange);
void SetEnumPropertyChoices(int property,
wpi::span<const std::string> choices,
std::span<const std::string> choices,
CS_Status* status);

private:
Expand Down
2 changes: 1 addition & 1 deletion cscore/src/main/native/cpp/CvSourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ CS_Property CreateSourcePropertyCallback(
}

void SetSourceEnumPropertyChoices(CS_Source source, CS_Property property,
wpi::span<const std::string> choices,
std::span<const std::string> choices,
CS_Status* status) {
auto data = Instance::GetInstance().GetSource(source);
if (!data || (data->kind & SourceMask) == 0) {
Expand Down
15 changes: 8 additions & 7 deletions cscore/src/main/native/cpp/HttpCameraImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void HttpCameraImpl::MonitorThreadMain() {
std::unique_lock lock(m_mutex);
// sleep for 1 second between checks
m_monitorCond.wait_for(lock, std::chrono::seconds(1),
[=] { return !m_active; });
[=, this] { return !m_active; });

if (!m_active) {
break;
Expand Down Expand Up @@ -110,7 +110,8 @@ void HttpCameraImpl::StreamThreadMain() {
m_streamConn->stream->close();
}
// Wait for enable
m_sinkEnabledCond.wait(lock, [=] { return !m_active || IsEnabled(); });
m_sinkEnabledCond.wait(lock,
[=, this] { return !m_active || IsEnabled(); });
if (!m_active) {
return;
}
Expand Down Expand Up @@ -329,7 +330,7 @@ void HttpCameraImpl::SettingsThreadMain() {
wpi::HttpRequest req;
{
std::unique_lock lock(m_mutex);
m_settingsCond.wait(lock, [=] {
m_settingsCond.wait(lock, [=, this] {
return !m_active || (m_prefLocation != -1 && !m_settings.empty());
});
if (!m_active) {
Expand Down Expand Up @@ -378,7 +379,7 @@ CS_HttpCameraKind HttpCameraImpl::GetKind() const {
return m_kind;
}

bool HttpCameraImpl::SetUrls(wpi::span<const std::string> urls,
bool HttpCameraImpl::SetUrls(std::span<const std::string> urls,
CS_Status* status) {
std::vector<wpi::HttpLocation> locations;
for (const auto& url : urls) {
Expand Down Expand Up @@ -572,14 +573,14 @@ CS_Source CreateHttpCamera(std::string_view name, std::string_view url,
break;
}
std::string urlStr{url};
if (!source->SetUrls(wpi::span{&urlStr, 1}, status)) {
if (!source->SetUrls(std::span{&urlStr, 1}, status)) {
return 0;
}
return inst.CreateSource(CS_SOURCE_HTTP, source);
}

CS_Source CreateHttpCamera(std::string_view name,
wpi::span<const std::string> urls,
std::span<const std::string> urls,
CS_HttpCameraKind kind, CS_Status* status) {
auto& inst = Instance::GetInstance();
if (urls.empty()) {
Expand All @@ -603,7 +604,7 @@ CS_HttpCameraKind GetHttpCameraKind(CS_Source source, CS_Status* status) {
return static_cast<HttpCameraImpl&>(*data->source).GetKind();
}

void SetHttpCameraUrls(CS_Source source, wpi::span<const std::string> urls,
void SetHttpCameraUrls(CS_Source source, std::span<const std::string> urls,
CS_Status* status) {
if (urls.empty()) {
*status = CS_EMPTY_VALUE;
Expand Down
4 changes: 2 additions & 2 deletions cscore/src/main/native/cpp/HttpCameraImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <functional>
#include <initializer_list>
#include <memory>
#include <span>
#include <string>
#include <string_view>
#include <thread>
Expand All @@ -18,7 +19,6 @@
#include <wpi/StringMap.h>
#include <wpi/condition_variable.h>
#include <wpi/raw_istream.h>
#include <wpi/span.h>
#include <wpinet/HttpUtil.h>

#include "SourceImpl.h"
Expand Down Expand Up @@ -55,7 +55,7 @@ class HttpCameraImpl : public SourceImpl {
void NumSinksEnabledChanged() override;

CS_HttpCameraKind GetKind() const;
bool SetUrls(wpi::span<const std::string> urls, CS_Status* status);
bool SetUrls(std::span<const std::string> urls, CS_Status* status);
std::vector<std::string> GetUrls() const;

// Property data
Expand Down
6 changes: 3 additions & 3 deletions cscore/src/main/native/cpp/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ class Instance {
void DestroySource(CS_Source handle);
void DestroySink(CS_Sink handle);

wpi::span<CS_Source> EnumerateSourceHandles(
std::span<CS_Source> EnumerateSourceHandles(
wpi::SmallVectorImpl<CS_Source>& vec) {
return m_sources.GetAll(vec);
}

wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec) {
std::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec) {
return m_sinks.GetAll(vec);
}

wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
std::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
wpi::SmallVectorImpl<CS_Sink>& vec) {
vec.clear();
m_sinks.ForEach([&](CS_Sink sinkHandle, const SinkData& data) {
Expand Down
2 changes: 1 addition & 1 deletion cscore/src/main/native/cpp/PropertyContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ int PropertyContainer::GetPropertyIndex(std::string_view name) const {
return ndx;
}

wpi::span<int> PropertyContainer::EnumerateProperties(
std::span<int> PropertyContainer::EnumerateProperties(
wpi::SmallVectorImpl<int>& vec, CS_Status* status) const {
if (!m_properties_cached && !CacheProperties(status)) {
return {};
Expand Down
4 changes: 2 additions & 2 deletions cscore/src/main/native/cpp/PropertyContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include <atomic>
#include <cstddef>
#include <memory>
#include <span>
#include <string>
#include <string_view>
#include <vector>

#include <wpi/StringMap.h>
#include <wpi/mutex.h>
#include <wpi/span.h>

#include "PropertyImpl.h"
#include "cscore_cpp.h"
Expand All @@ -33,7 +33,7 @@ class PropertyContainer {
virtual ~PropertyContainer() = default;

int GetPropertyIndex(std::string_view name) const;
wpi::span<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
std::span<int> EnumerateProperties(wpi::SmallVectorImpl<int>& vec,
CS_Status* status) const;
CS_PropertyKind GetPropertyKind(int property) const;
std::string_view GetPropertyName(int property,
Expand Down
4 changes: 2 additions & 2 deletions cscore/src/main/native/cpp/SourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Frame SourceImpl::GetCurFrame() {
Frame SourceImpl::GetNextFrame() {
std::unique_lock lock{m_frameMutex};
auto oldTime = m_frame.GetTime();
m_frameCv.wait(lock, [=] { return m_frame.GetTime() != oldTime; });
m_frameCv.wait(lock, [=, this] { return m_frame.GetTime() != oldTime; });
return m_frame;
}

Expand All @@ -85,7 +85,7 @@ Frame SourceImpl::GetNextFrame(double timeout) {
auto oldTime = m_frame.GetTime();
if (!m_frameCv.wait_for(
lock, std::chrono::milliseconds(static_cast<int>(timeout * 1000)),
[=] { return m_frame.GetTime() != oldTime; })) {
[=, this] { return m_frame.GetTime() != oldTime; })) {
m_frame = Frame{*this, "timed out getting frame", wpi::Now()};
}
return m_frame;
Expand Down
6 changes: 3 additions & 3 deletions cscore/src/main/native/cpp/UnlimitedHandleResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#define CSCORE_UNLIMITEDHANDLERESOURCE_H_

#include <memory>
#include <span>
#include <utility>
#include <vector>

#include <wpi/SmallVector.h>
#include <wpi/mutex.h>
#include <wpi/span.h>

namespace cs {

Expand Down Expand Up @@ -50,7 +50,7 @@ class UnlimitedHandleResource {
std::shared_ptr<TStruct> Free(THandle handle);

template <typename T>
wpi::span<T> GetAll(wpi::SmallVectorImpl<T>& vec);
std::span<T> GetAll(wpi::SmallVectorImpl<T>& vec);

std::vector<std::shared_ptr<TStruct>> FreeAll();

Expand Down Expand Up @@ -151,7 +151,7 @@ UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::Free(

template <typename THandle, typename TStruct, int typeValue, typename TMutex>
template <typename T>
inline wpi::span<T>
inline std::span<T>
UnlimitedHandleResource<THandle, TStruct, typeValue, TMutex>::GetAll(
wpi::SmallVectorImpl<T>& vec) {
ForEach([&](THandle handle, const TStruct& data) { vec.push_back(handle); });
Expand Down
10 changes: 5 additions & 5 deletions cscore/src/main/native/cpp/cscore_cpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ CS_Property GetSourceProperty(CS_Source source, std::string_view name,
return Handle{source, property, Handle::kProperty};
}

wpi::span<CS_Property> EnumerateSourceProperties(
std::span<CS_Property> EnumerateSourceProperties(
CS_Source source, wpi::SmallVectorImpl<CS_Property>& vec,
CS_Status* status) {
auto data = Instance::GetInstance().GetSource(source);
Expand Down Expand Up @@ -398,7 +398,7 @@ std::vector<VideoMode> EnumerateSourceVideoModes(CS_Source source,
return data->source->EnumerateVideoModes(status);
}

wpi::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
std::span<CS_Sink> EnumerateSourceSinks(CS_Source source,
wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status) {
auto& inst = Instance::GetInstance();
Expand Down Expand Up @@ -583,7 +583,7 @@ CS_Property GetSinkProperty(CS_Sink sink, std::string_view name,
return Handle{sink, property, Handle::kSinkProperty};
}

wpi::span<CS_Property> EnumerateSinkProperties(
std::span<CS_Property> EnumerateSinkProperties(
CS_Sink sink, wpi::SmallVectorImpl<CS_Property>& vec, CS_Status* status) {
auto data = Instance::GetInstance().GetSink(sink);
if (!data) {
Expand Down Expand Up @@ -865,12 +865,12 @@ void Shutdown() {
// Utility Functions
//

wpi::span<CS_Source> EnumerateSourceHandles(
std::span<CS_Source> EnumerateSourceHandles(
wpi::SmallVectorImpl<CS_Source>& vec, CS_Status* status) {
return Instance::GetInstance().EnumerateSourceHandles(vec);
}

wpi::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
std::span<CS_Sink> EnumerateSinkHandles(wpi::SmallVectorImpl<CS_Sink>& vec,
CS_Status* status) {
return Instance::GetInstance().EnumerateSinkHandles(vec);
}
Expand Down
Loading

0 comments on commit fbdc810

Please sign in to comment.