C++
LLVM Coding Standard
All C++ code should comply with the LLVM Coding Standard. This standard aims to increase the readability and maintainability of the codebase. On top of that we use Clang Format, which enables a set of configurable formatting style options that comply with the LLVM standard.
Tools such as Clang-Tidy or run-clang-format.py enable us to enforce the per project defined LLVM compliant formatting style. In order to auto-format, the tool clang-format is recommended. This tool is part of the Clang Format toolset and hence also documented there, furthermore it is available as a standalone package in standard Linux and macOS repositories. When working on older Linux distros (e.g. Ubuntu 14.0.4) the standard available clang-format version may be backwards incompatible with the version required to comply with the formatting defined by the project, in that case it is recommended to try installing an alternative updated version, or to execute the tool from within a dockerized environment.
To auto-format the code with clang-format;
clang-format -i <file.cpp>
In some exceptional cases we may want to deviate from the coding standard, this can be accomplished as follows:
// clang-format off.. non LLVM compliant code here// clang-format on
Prefixes
In order to prevent naming collisions and to easily distinguish between local and member variables, the following prefixes are used:
Prefix | Description |
---|---|
m_ | Class member variables |
s_ | Local static variables which are defined outside a function |
NB: The usage of this->
is discouraged as it adds an extra layer of
pointer complexity (especially when dealing with double or triple
pointers). The usage of m_ fully prevents the case where this is
needed (e.g. due a variable which is overridden in scope due similar
naming).
Doxygen
Doxygen docstring formatting is used for
generating C++ documentation. For a full overview of the available
commands see:
Doxygen-command-overview.
Doxygen supports both \ and @ for defining commands and, supports
both /** ... */
and /// ...
for defining docstrings, in line
with the LLVM coding standard we always stick to the following
conventions:
Prefix | Description |
---|---|
@ | Command definition |
/// | Docstring definition |