aseba icon indicating copy to clipboard operation
aseba copied to clipboard

Update codebase to C++14

Open stephanemagnenat opened this issue 7 years ago • 12 comments

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, keyword using 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, using cbegin() and cend().
  • 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

stephanemagnenat avatar Apr 04 '17 08:04 stephanemagnenat

Commit 05d3b36710b0f09557925c0573873fecf8ed4aec updates common/msg to C++11 following these rules.

stephanemagnenat avatar Apr 05 '17 15:04 stephanemagnenat

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.

THS-on avatar Apr 17 '17 19:04 THS-on

Commit c4c5307 adds the missing files in 05d3b36710b0f09557925c0573873fecf8ed4aec, thank you for reporting the problem!

stephanemagnenat avatar Apr 18 '17 13:04 stephanemagnenat

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.

stephanemagnenat avatar Sep 22 '17 09:09 stephanemagnenat

Commit 9802ba91 updates compiler.

stephanemagnenat avatar Sep 22 '17 09:09 stephanemagnenat

Commit 8b6e0f4e updates common/utils.

stephanemagnenat avatar Sep 22 '17 09:09 stephanemagnenat

Commit 80f6bae7 finishes updating common/msg.

stephanemagnenat avatar Sep 22 '17 09:09 stephanemagnenat

Commit daaf1be3 updates common/zeroconf.

stephanemagnenat avatar Sep 22 '17 10:09 stephanemagnenat

Or you could use a compilation database

cor3ntin avatar Feb 01 '18 08:02 cor3ntin

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 avatar Feb 01 '18 09:02 davidjsherman

@davidjsherman cmake does it, yes https://cmake.org/cmake/help/v3.5/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

cor3ntin avatar Feb 01 '18 09:02 cor3ntin

@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?

davidjsherman avatar Feb 01 '18 09:02 davidjsherman