General#

Reference Version#

The current reference version for C++ is the C++17 standard.

The reference compiler is the GNU Compiler Collection, version 11, currently at version 11.4.

It is also recommended to test software against the Clang compiler, version 16 and use the accompanying code-formatting and static analysis tools, see Auto-Formatting and Static Code Checks.

Packages for Alma Linux 9, the current reference OS, are available:

For the GCC c++ compiler:

# dnf install gcc-c++

For clang++, clang-format and clang-tidy:

# dnf install clang clang-extra-tools

General High-Level Recommendations#

Libraries#

Todo

Add libraries

Tools and Configurations#

Template Project#

A template project that is kept up-to-date with the recommendations given here is available in the CTAO Gitlab, also see Project Structure and Build System.

Unit tests#

The recommended framework for unit tests is GoogleTest using a git submodule pointing to a release tag.

Documentation#

The recommended tool for API documentation is doxygen.

Static Code Checks#

It is recommended to run clang-tidy static code-checks on the code base as part of the CI system. The exact checks to be included will be updated here and more checks can be added by projects to enforce stricter standards:

Checks: 'clang-diagnostic-*,clang-analyzer-*,clang-analyzer-cpluscplus*,cppcoreguidelines-*,readability-isolate-declaration'
WarningsAsErrors: '*'

Existing code bases should start with the minimal set of checks that succeed and make an effort to fix complaints to be able to enable more checks in the CI.

Auto-Formatting#

Code should be auto-formatted using clang-format using the following configuration:

BasedOnStyle: Google
ColumnLimit: 88
IndentWidth: 4
Language: Cpp
DerivePointerAlignment: false
PointerAlignment: Left

It is possible to enforce this also using pre-commit using the following .pre-commit-config.yaml:

repos:
  - repo: https://github.com/pre-commit/mirrors-clang-format
    rev: v16.0.3
    hooks:
    - id: clang-format

The template project also contains configuration to run this as part of the CI in the .gitlab-ci.ymal.

General Code Style#

CTAO C++ code shall follow the Google C++ Style Guide, with a few notable exceptions:

  • We do not forbid exceptions, it is the preferred way to handle error conditions.

  • We use an indentation of 4 instead of 2 spaces (see above).