aseba
aseba copied to clipboard
Update codebase to C++14
The current Aseba codebase is mostly C++03. Recently, Aseba has been switched to C++14, and new code is expected to use the new C++14 features. Progressively, existing code should be migrated.
The following features should be used:
-
override: methods that override parent ones should explicitly state that through the
override
keyword. -
noexcept: functions that are guaranteed not to return exception should state that through the
noexcept
keyword. -
constexpr: objects and functions that can be const expressions should state that through the
constexpr
keyword. -
autogenm: in interfaces with virtual destructors, when not manually specified, the following auto-generated members should be specified as
default
: copy constructor, copy assignment operator, move constructor, move assignment operator. - defval: when it makes sense, class members should be given default values to simplify the constructors.
-
usingalias: instead of
typedef
, keywordusing
should be for template aliasing. - enum: use strongly-typed enums whenever meaningful.
- nullptr: use nullptr whenever a NULL pointer is used.
- auto: use auto and range-based loops whenever it makes sense.
-
contstit: use
const_iterator
whenever possible, usingcbegin()
andcend()
. -
array: use
std::array
instead of C arrays. -
passbyvalue: when a constructor copies a variable into its own, pass by value and
std::move
.
The following code parts of Aseba must be updated:
- [x]
common/
- [x]
compiler/
- [ ]
transport/dashel_plugins
- [ ]
clients/studio
- [ ]
clients/thymioupgrader
- [ ]
clients/thymiownetconfig
- [ ] other tools in
clients/
- [ ]
switches
- [ ]
targets
- [ ]
examples
Commit 05d3b36710b0f09557925c0573873fecf8ed4aec updates common/msg
to C++11 following these rules.
Commit 05d3b36710b0f09557925c0573873fecf8ed4aec breaks build process because in tests/CMakeLists.txt the directory "msg" is defined, but is missing.
If the line is removed building works fine.
Commit c4c5307 adds the missing files in 05d3b36710b0f09557925c0573873fecf8ed4aec, thank you for reporting the problem!
A large part of this can be done automatically, with supervision, using clang-tidy
. With FILENAME
as the cpp file to process, one can preview the changes with:
clang-tidy -checks='modernize-*' -header-filter='.*' FILENAME -- -std=c++11
and apply them with:
clang-tidy -checks='modernize-*' -header-filter='.*' -fix FILENAME -- -std=c++11
Additional include options should be given after -std=c++11
when relevant.
Commit 9802ba91 updates compiler
.
Commit 8b6e0f4e updates common/utils
.
Commit 80f6bae7 finishes updating common/msg
.
Commit daaf1be3 updates common/zeroconf
.
Or you could use a compilation database
Is there a way to produce a compilation database that is compatible with Sonarqube?
Currently we produce one using build-wrapper
from SonarCFamily for C/C++ but it is sometimes a bit flaky and also closed-source.
@davidjsherman cmake does it, yes https://cmake.org/cmake/help/v3.5/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html
@cor3ntin: Do you know whether they are compatible? If you can generate one, I can test it with sonar-scanner.
How do you recommend managing the three different compilation databases for the three different build environments?