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:
Tyler Veness
2022-10-15 16:33:14 -07:00
committed by GitHub
parent 396143004c
commit fbdc810887
355 changed files with 1659 additions and 2918 deletions

View File

@@ -89,7 +89,7 @@
#ifndef WPIUTIL_WPI_CONVERTUTF_H
#define WPIUTIL_WPI_CONVERTUTF_H
#include "wpi/span.h"
#include <span>
#include <cstddef>
#include <string>
@@ -259,7 +259,7 @@ inline ConversionResult convertUTF8Sequence(const UTF8 **source,
* Returns true if a blob of text starts with a UTF-16 big or little endian byte
* order mark.
*/
bool hasUTF16ByteOrderMark(span<const char> SrcBytes);
bool hasUTF16ByteOrderMark(std::span<const char> SrcBytes);
/**
* Converts a stream of raw bytes assumed to be UTF16 into a UTF8 std::string.
@@ -268,7 +268,7 @@ bool hasUTF16ByteOrderMark(span<const char> SrcBytes);
* \param [out] Out Converted UTF-8 is stored here on success.
* \returns true on success
*/
bool convertUTF16ToUTF8String(span<const char> SrcBytes, SmallVectorImpl<char> &Out);
bool convertUTF16ToUTF8String(std::span<const char> SrcBytes, SmallVectorImpl<char> &Out);
/**
* Converts a UTF16 string into a UTF8 std::string.
@@ -277,7 +277,7 @@ bool convertUTF16ToUTF8String(span<const char> SrcBytes, SmallVectorImpl<char> &
* \param [out] Out Converted UTF-8 is stored here on success.
* \returns true on success
*/
bool convertUTF16ToUTF8String(span<const UTF16> Src, SmallVectorImpl<char> &Out);
bool convertUTF16ToUTF8String(std::span<const UTF16> Src, SmallVectorImpl<char> &Out);
/**
* Converts a UTF-8 string into a UTF-16 string with native endianness.

View File

@@ -21,11 +21,10 @@
#include <cstddef>
#include <memory>
#include <span>
#include <string_view>
#include <system_error>
#include "wpi/span.h"
// Duplicated from fs.h to avoid a dependency
namespace fs {
#if defined(_WIN32)
@@ -61,7 +60,7 @@ class MemoryBuffer {
const uint8_t* end() const { return m_bufferEnd; }
size_t size() const { return m_bufferEnd - m_bufferStart; }
span<const uint8_t> GetBuffer() const { return {begin(), end()}; }
std::span<const uint8_t> GetBuffer() const { return {begin(), end()}; }
/// Return an identifier for this buffer, typically the filename it was read
/// from.
@@ -98,14 +97,14 @@ class MemoryBuffer {
/// Open the specified memory range as a MemoryBuffer.
static std::unique_ptr<MemoryBuffer> GetMemBuffer(
span<const uint8_t> inputData, std::string_view bufferName = "");
std::span<const uint8_t> inputData, std::string_view bufferName = "");
static std::unique_ptr<MemoryBuffer> GetMemBuffer(MemoryBufferRef ref);
/// Open the specified memory range as a MemoryBuffer, copying the contents
/// and taking ownership of it.
static std::unique_ptr<MemoryBuffer> GetMemBufferCopy(
span<const uint8_t> inputData, std::string_view bufferName = "");
std::span<const uint8_t> inputData, std::string_view bufferName = "");
/// Map a subrange of the specified file as a MemoryBuffer.
static std::unique_ptr<MemoryBuffer> GetFileSlice(std::string_view filename,
@@ -145,7 +144,7 @@ class WritableMemoryBuffer : public MemoryBuffer {
// guaranteed to have been initialized with a mutable buffer.
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
span<uint8_t> GetBuffer() { return {begin(), end()}; }
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
static std::unique_ptr<WritableMemoryBuffer> GetFile(
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
@@ -196,7 +195,7 @@ class WriteThroughMemoryBuffer : public MemoryBuffer {
// guaranteed to have been initialized with a mutable buffer.
uint8_t* begin() { return const_cast<uint8_t*>(MemoryBuffer::begin()); }
uint8_t* end() { return const_cast<uint8_t*>(MemoryBuffer::end()); }
span<uint8_t> GetBuffer() { return {begin(), end()}; }
std::span<uint8_t> GetBuffer() { return {begin(), end()}; }
static std::unique_ptr<WriteThroughMemoryBuffer> GetFile(
std::string_view filename, std::error_code& ec, int64_t fileSize = -1);
@@ -218,22 +217,22 @@ class WriteThroughMemoryBuffer : public MemoryBuffer {
};
class MemoryBufferRef {
span<const uint8_t> m_buffer;
std::span<const uint8_t> m_buffer;
std::string_view m_id;
public:
MemoryBufferRef() = default;
MemoryBufferRef(MemoryBuffer& buffer) // NOLINT
: m_buffer(buffer.GetBuffer()), m_id(buffer.GetBufferIdentifier()) {}
MemoryBufferRef(span<const uint8_t> buffer, std::string_view id)
MemoryBufferRef(std::span<const uint8_t> buffer, std::string_view id)
: m_buffer(buffer), m_id(id) {}
span<const uint8_t> GetBuffer() const { return m_buffer; }
std::span<const uint8_t> GetBuffer() const { return m_buffer; }
std::string_view GetBufferIdentifier() const { return m_id; }
const uint8_t* begin() const { return m_buffer.begin(); }
const uint8_t* end() const { return m_buffer.end(); }
const uint8_t* begin() const { return &*m_buffer.begin(); }
const uint8_t* end() const { return &*m_buffer.end(); }
size_t size() const { return m_buffer.size(); }
};

View File

@@ -14,7 +14,7 @@
#define WPIUTIL_WPI_RAW_OSTREAM_H
#include "wpi/SmallVector.h"
#include "wpi/span.h"
#include <span>
#include <cassert>
#include <cstddef>
#include <cstdint>
@@ -199,7 +199,7 @@ public:
return *this;
}
raw_ostream &operator<<(span<const uint8_t> Arr) {
raw_ostream &operator<<(std::span<const uint8_t> Arr) {
// Inline fast path, particularly for arrays with a known length.
size_t Size = Arr.size();
@@ -675,9 +675,9 @@ public:
void flush() = delete;
/// Return an span for the vector contents.
span<uint8_t> array() { return {OS.data(), OS.size()}; }
span<const uint8_t> array() const { return {OS.data(), OS.size()}; }
/// Return an std::span for the vector contents.
std::span<uint8_t> array() { return {OS.data(), OS.size()}; }
std::span<const uint8_t> array() const { return {OS.data(), OS.size()}; }
};
/// A raw_ostream that writes to a vector. This is a
@@ -709,9 +709,9 @@ public:
void flush() = delete;
/// Return a span for the vector contents.
span<uint8_t> array() { return {OS.data(), OS.size()}; }
span<const uint8_t> array() const { return {OS.data(), OS.size()}; }
/// Return a std::span for the vector contents.
std::span<uint8_t> array() { return {OS.data(), OS.size()}; }
std::span<const uint8_t> array() const { return {OS.data(), OS.size()}; }
};