Fix build warnings/errors in C++20 #2883
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
FlashString static initialisation
The
Object
copy and move constructors are deleted as a precaution as these objects should not be copied.C++20 doesn't like this so they're only compiled for C++17 and earlier.
std:is_pod deprecated
Use std::is_standard_layout instead (only one instance to correct).
Volatile
C++20 deprecates many uses of
volatile
which may be implemented in an ambiguous (non-deterministic) way.Largely these uses are concerned with threaded applications. A general web search turns up plenty of articles on this.
One argument is related to code like this:
So we should identify all such cases and code them more explicitly.
The FIFO/FILO classes define
numberOfElements
as volatile but I can see no reason why this needs to be the case.Volatile bitwise operations
C++23 will, it seems, de-deprecate use of volatile for bitwise operations.
This is discussed here https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2327r1.pdf.
See also earlephilhower/arduino-pico#1379
These are genuine uses of volatile as values are used both in interrupt and task context. Some of these actually need to be atomic, and the assumption is probably that
x |= n
does that. Hence the ambiguity. These are the core Sming files affected:There will be many others in libraries.
Solution: Rather than attempting to 'correct' the code and introduce bugs - risks identified in the above paper - it is safer to just silence this particular warning. This has been done in the main Sming
build.mk
file so it's easy to revert if required. This is thevolatile
warning which covers other uses as well - future GCC revisions may add some granularity to this.FIFO / FILO uses int instead of unsigned
No warnings but using
int
for the count makes no sense.Not related to C++20 but since we're modifying the classes anyway may as well do it here.