Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build warnings/errors in C++20 #2883

Merged
merged 2 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sming/Components/FlashString
2 changes: 1 addition & 1 deletion Sming/Components/Storage/src/include/Storage/Partition.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ class Partition
bool read(storage_size_t offset, void* dst, size_t size);

template <typename T>
typename std::enable_if<std::is_pod<T>::value, bool>::type read(storage_size_t offset, T& value)
typename std::enable_if<std::is_standard_layout<T>::value, bool>::type read(storage_size_t offset, T& value)
{
return read(offset, &value, sizeof(value));
}
Expand Down
20 changes: 10 additions & 10 deletions Sming/Wiring/FIFO.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@

#include "Countable.h"

template <typename T, int rawSize> class FIFO : public Countable<T>
template <typename T, unsigned rawSize> class FIFO : public Countable<T>
{
public:
const int size; // speculative feature, in case it's needed
const unsigned size; // speculative feature, in case it's needed

FIFO();

Expand Down Expand Up @@ -60,18 +60,18 @@ template <typename T, int rawSize> class FIFO : public Countable<T>
}

protected:
volatile int numberOfElements;
int nextIn;
int nextOut;
unsigned numberOfElements;
unsigned nextIn;
unsigned nextOut;
T raw[rawSize];
};

template <typename T, int rawSize> FIFO<T, rawSize>::FIFO() : size(rawSize)
template <typename T, unsigned rawSize> FIFO<T, rawSize>::FIFO() : size(rawSize)
{
flush();
}

template <typename T, int rawSize> bool FIFO<T, rawSize>::enqueue(T element)
template <typename T, unsigned rawSize> bool FIFO<T, rawSize>::enqueue(T element)
{
if(full()) {
return false;
Expand All @@ -85,7 +85,7 @@ template <typename T, int rawSize> bool FIFO<T, rawSize>::enqueue(T element)
return true;
}

template <typename T, int rawSize> T FIFO<T, rawSize>::dequeue()
template <typename T, unsigned rawSize> T FIFO<T, rawSize>::dequeue()
{
T item;
numberOfElements--;
Expand All @@ -95,12 +95,12 @@ template <typename T, int rawSize> T FIFO<T, rawSize>::dequeue()
return item;
}

template <typename T, int rawSize> T FIFO<T, rawSize>::peek() const
template <typename T, unsigned rawSize> T FIFO<T, rawSize>::peek() const
{
return raw[nextOut];
}

template <typename T, int rawSize> void FIFO<T, rawSize>::flush()
template <typename T, unsigned rawSize> void FIFO<T, rawSize>::flush()
{
nextIn = nextOut = numberOfElements = 0;
}
Expand Down
20 changes: 10 additions & 10 deletions Sming/Wiring/FILO.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

#include "Countable.h"

template <typename T, int rawSize> class FILO : public Countable<T>
template <typename T, unsigned rawSize> class FILO : public Countable<T>
{
public:
const int size; // speculative feature, in case it's needed
const unsigned size; // speculative feature, in case it's needed

FILO();

Expand Down Expand Up @@ -59,18 +59,18 @@ template <typename T, int rawSize> class FILO : public Countable<T>
}

private:
volatile int numberOfElements;
int nextIn;
int nextOut;
unsigned numberOfElements;
unsigned nextIn;
unsigned nextOut;
T raw[rawSize];
};

template <typename T, int rawSize> FILO<T, rawSize>::FILO() : size(rawSize)
template <typename T, unsigned rawSize> FILO<T, rawSize>::FILO() : size(rawSize)
{
flush();
}

template <typename T, int rawSize> bool FILO<T, rawSize>::push(T element)
template <typename T, unsigned rawSize> bool FILO<T, rawSize>::push(T element)
{
if(count() >= rawSize) {
return false;
Expand All @@ -79,23 +79,23 @@ template <typename T, int rawSize> bool FILO<T, rawSize>::push(T element)
return true;
}

template <typename T, int rawSize> T FILO<T, rawSize>::pop()
template <typename T, unsigned rawSize> T FILO<T, rawSize>::pop()
{
if(numberOfElements > 0) {
return raw[--numberOfElements];
}
return raw[0];
}

template <typename T, int rawSize> T FILO<T, rawSize>::peek() const
template <typename T, unsigned rawSize> T FILO<T, rawSize>::peek() const
{
if(numberOfElements > 0) {
return raw[numberOfElements - 1];
}
return raw[0];
}

template <typename T, int rawSize> void FILO<T, rawSize>::flush()
template <typename T, unsigned rawSize> void FILO<T, rawSize>::flush()
{
nextIn = nextOut = numberOfElements = 0;
}
5 changes: 5 additions & 0 deletions Sming/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ COMPILER_VERSION_FULL := $(shell LANG=C $(CC) -v 2>&1 | $(AWK) -F " version " '/
COMPILER_NAME := $(word 1,$(COMPILER_VERSION_FULL))
COMPILER_VERSION := $(word 2,$(COMPILER_VERSION_FULL))

# Use of bitwise assignment for volatile registers is deprecated in C++20 but de-deprecated in C++23
ifeq ($(COMPILER_NAME)-$(SMING_CXX_STD),gcc-c++20)
CXXFLAGS += -Wno-volatile
endif

ifndef USE_CLANG
# Required to access peripheral registers using structs
# e.g. `uint32_t value: 8` sitting at a byte or word boundary will be 'optimised' to
Expand Down
Loading