On this page
  1. Who decides
  2. Every rule, and what holds it
  3. Shown, and checked like the code
  4. What a game gets
    1. Switching on the framework's clang-tidy

Guidelines

How C++ is written here: in the framework, in its examples, and in a game that wants to read like them. In the framework and the examples the rules on these pages are mandatory, and a tool holds every one a tool can tell apart from its mistake; in a game they are advice, and the game decides how much of the tooling it takes. When a question has more than one good answer, three sources decide it, in this order.

Who decides#

  1. The API is as simple as possible for whoever uses it. This outranks every other rule. A main menu is three functions, and a rule that would make it longer loses, whatever else it buys. The three-function menu says why.
  2. The rules on these pages, each with its reason: the naming table, the layout, const, no raw pointer, and nothing owned by hand, text in and out, the C++ written where C would also compile and macros — and the framework's own decisions in why it is built this way, such as one header per module and no exceptions.
  3. Google's C++ Style Guide, for everything the first two leave open. Where the framework has decided otherwise its decision holds, and Google's guide, and where this one differs lists each place with its reason.

Every rule, and what holds it#

A rule written only in a document is kept until the day somebody has not read it. So wherever a mistake can be described precisely, a tool refuses it: a check of clang-tidy, which rmp lint runs; a gate, which is a stage of rmp test; clang-format; or the compiler. One line per page of these Guidelines, with every tool that page names and where it holds — in the framework (its include/, src/ and tests/), in its examples, and in a game made with rmp new:

RulesChecked byFrameworkExamplesA game
Naming: one spelling per kind, no prefix, no name hiding another, no constant named like a macro, no retired namereadability-identifier-naming, clang-diagnostic-shadow; tools/naming_check.sh, rules R1 to R8, in every branch of every #ifyesyesno
Formatting: 4 spaces, 90 columns, no alignment, char *p, { 1, 2 }.clang-format; rmp fmt applies it, rmp fmt check and rmp test fmt refuse a file it would changeyesyesyes: rmp fmt formats and rmp fmt check refuses, when the game runs them
const: on every local and method that changes nothing, not on a parameter in a declaration, inline constexpr in a headermisc-const-correctness, readability-make-member-function-const, readability-avoid-const-params-in-decls, performance-unnecessary-value-param, custom-rmp-header-constantyesyes, but for readability-make-member-function-const and readability-avoid-const-params-in-declsno
Pointers and RAII: no raw pointer, no C string a game can name, an optional asked before it is read, nothing owned by hand, raylib's resources loaded only by their ownerscustom-rmp-raw-pointer, cppcoreguidelines-owning-memory, cppcoreguidelines-no-malloc, bugprone-unchecked-optional-access; tools/pointer_check.py; tools/ownership_check.sh O1 O2yes, with what tools/lint_debt.txt and tools/pointer_ratchet.txt still owe, and tools/ownership_check.sh in include/rmp/ and src/rmp/ onlyyes, but for tools/pointer_check.py and O1, which read only the framework's own code, and with what tools/lint_debt.txt still owesno
Strings: a view in, a std::string out, never a view's data() to raylib, nothing newer than the oldest compilertools/pointer_check.py, custom-rmp-raw-pointer, bugprone-dangling-handle, bugprone-suspicious-stringview-data-usage; tools/style_check.sh S4 S5yes, but for S4 in tests/, which build only on CI's compilersyes, but for tools/pointer_check.py, which reads only include/rmp/no
Modern C++: std::array, static_cast, enum class, nullptr, no varargs, int, explicit, ++i, designated initialisers in order, C++20 as GCC 10.5 has itmodernize-avoid-c-arrays, modernize-avoid-c-style-cast, cppcoreguidelines-use-enum-class, modernize-use-nullptr, modernize-avoid-variadic-functions, google-runtime-int, google-runtime-float, google-explicit-constructor, cppcoreguidelines-special-member-functions, modernize-use-auto, modernize-use-using, modernize-use-std-numbers, google-build-using-namespace, google-default-arguments; tools/style_check.sh S1 S2 S4 S5 S6; -Werror=reorder-init-listyes, but for S4 in tests/yes, but for modernize-use-autoonly the order of designated initialisers, which the compiler refuses
Macros: only for what a function cannot do, named RMP_cppcoreguidelines-macro-usage, readability-identifier-naming; tools/naming_check.sh R5 R6 R7yesyesno
Where Google's guide and these agree: no unnamed namespace or global using-declaration in a header, no overloaded unary &, no TODOgoogle-build-namespaces, google-global-names-in-headers, google-runtime-operator, google-build-explicit-make-pair; tools/style_check.sh S3yesyesno
No finding of a second analyser, and a reason beside every suppressiontools/cppcheck_check.shyes: src/rmp/nono
Warnings on the code we write-Wall -Wextrayes, as errors in the framework's own checksyesyes, as warnings

What checks what takes the same rules one by one, with each check's exact reach, the checks the framework switches off and why, and what the code still owes. The build of this site holds both tables to the framework's own configuration: a check said to run there runs there.

The rest of what the framework checks is not about how the code reads, and holds it together instead:

RuleChecked byFrameworkExamplesA game
Every public header compiles on its own and carries the .toml valuestools/header_check.shyes: include/rmp/nono
What each public header costs to includetools/header_cost.py, against tools/header_budget.txtyes: include/rmp/nono
Nothing in the framework reads the clock, the input or the random state on its owntools/seam_check.shyes: src/rmp/nono
A mistake in the .toml stops before the buildtools/configure.py, and tests/configure_test.py for each refusalyesno: they are built with the framework'syes
Every vendored component has a licence the project can shiptools/license_db.pyyesnoyes: rmp test config
No memory error and no undefined behaviour in a runAddressSanitizer and UndefinedBehaviorSanitizer in every debug build, from cmake/sanitize.cmake; tools/sanitize_check.sh for a second compileryesyesno, until its [dev] sanitize lists them
Every release binary stays the size it was measured at, unless the growth is written downtools/size_check.py, against tools/size_budget.txtyesnoyes, from the day it commits a budget of its own
No file of the framework falls below the share of its lines its tests are written down to run, and no public function arrives without a test that calls ittools/coverage_report.py, against tools/coverage_floor.txt and tools/untested_api.txtyes: src/rmp/ and include/rmp/nono
Generated input looks for what no test was written for: properties against generated values, every committed fuzz input replayed, each module's mutation score held to a floor that only rises; and nothing in the framework throwstools/fuzz.sh, tools/mutation.sh against tests/mutation/floors/, RapidCheck and Hypothesis, all held together by tests/campaign_test.pyyesnono

Each is a stage of rmp test or a step of the framework's CI, and Testing has where and when each one runs.

Shown, and checked like the code#

Each rule is shown in code, and the code on these pages is checked the way the framework's own is. A block that shows the right way is compiled against the framework's headers, and passes, with nothing to say, clang-tidy with the framework's .clang-tidy, clang-format with its .clang-format, and its text gates: tools/naming_check.sh, tools/style_check.sh, tools/ownership_check.sh and, for a block that is a public header, tools/pointer_check.py. A block that shows the wrong way says what refuses it, and the build of this site runs that tool on it and fails if it stays quiet; what the tool printed is under the block, from that run, never typed. A block that does not compile at all is shown with what the compiler said.

What a game gets#

A game made with rmp new gets two things from these pages, and the rest is advice:

  • .clang-format, so rmp fmt lays out the game's code the framework's way, and rmp fmt check refuses a file that is not. Neither runs unless the game runs it: its rmp test and its CI leave the layout alone.
  • -Werror=reorder-init-list, which the framework's library hands every target that links it: under Clang, designated initialisers out of declaration order are an error, as they already are under GCC and MSVC.

Its own code is also compiled with the warnings the framework's is: -Wall -Wextra under GCC and Clang, with -Wno-missing-field-initializers, because leaving fields of an options struct out — { .width = 8 } — is how the API is written. That is every build CMake makes, the desktop's and the web's; Android's and iOS's own projects build without them. They stay warnings: a newer compiler on its author's machine must not stop a build that was fine yesterday. A game can configure with -DRMP_WERROR=ON to make them errors, as the framework's own checks do. The vendored libraries are included as system headers, so the warnings are about the game's code and not about theirs.

It does not get the framework's .clang-tidy, its text gates or its cppcheck: rmp lint is a command of the framework's own repository, and in a game it says so and stops.

Switching on the framework's clang-tidy#

There is no setting in the .toml for it. A game that wants the framework's checks on its own code copies the framework's .clang-tidy into its root and runs clang-tidy itself. The game already has what clang-tidy needs: its CMakePresets.json is the framework's, and the lint preset writes the compile database without building anything.

cp ~/.local/share/rmp/.clang-tidy .
cmake --preset lint
clang-tidy -p build/lint --experimental-custom-checks --warnings-as-errors='*' \
    --header-filter='.*/(include|src|tests)/.*' \
    --exclude-header-filter='.*/(include/rmp|src/rmp|thirdparty|generated|build)/.*' \
    $(find src tests -name '*.cpp' -not -path 'src/rmp/*')
  • The .clang-tidy is the one of the framework rmp runs from: the clone rmp install made, in ~/.local/share/rmp on Linux and macOS and in %LOCALAPPDATA%\rmp on Windows.
  • --experimental-custom-checks runs the two queries of the framework's own, the raw pointer and the constant in a header; without it clang-tidy skips them and says nothing. The framework pins clang-tidy 22.1.8, in thirdparty/FROZEN_VERSIONS.md, and its file is written for that one.
  • --warnings-as-errors='*' makes a finding fail the run, which is what a check is for. The framework's file says WarningsAsErrors: '' because rmp lint counts its warnings against a list of what the framework still owes.
  • --header-filter reports the game's own headers in include/, src/ and tests/. The framework's file names the folders it reports by the framework's layout, and a header in a game's include/, where the examples keep theirs, is not among them: without the flag, a C cast there passes in silence.
  • --exclude-header-filter keeps the framework's copy in include/rmp/ and src/rmp/ out of the report: the framework answers for those files, and its lint still owes some of them a few raw pointers.
  • The copy asks every macro defined to start with RMP_, the framework's prefix. A game whose own macros take the game's name instead, as Macros advises, writes that name in its copy's MacroDefinitionPrefix; with 'RMP_' left there, clang-tidy refuses #define PONG_SHOW(value) in the game's code.

The last line hands it every source of the game's own — src/ and tests/, without the framework's copy in src/rmp/. clang-tidy then says nothing about the game rmp new writes, its test included, and refuses a C cast added to its main menu, or to a header of its own in include/, the way the framework's lint would.