Skip to content

Coding standards

Kokeb Labs code follows named, published coding standards, so that a reviewer, an auditor or a customer can check our claims against a reference they already know.

Standard Used for How we follow it
MISRA C++:2023 (with TC1:2026) C++ code Reference standard. A compliance matrix classifies every guideline (below).
MISRA C:2025 C code Reference standard; its compliance matrix follows the same format (not written yet).
SEI CERT C++ and CERT C Security baseline Every rule an open tool can decide is checked by clang-tidy (cert-*) or cppcheck.
C++ Core Guidelines Design and idiom Followed through the clang-tidy cppcoreguidelines-* checks and the Standards pages.
NASA/JPL Power of Ten Embedded discipline Covered by rules on memory, loops and checking every result.

What "follows MISRA" means here

We use the approach MISRA itself defines in MISRA Compliance:2020:

  1. Guideline enforcement plan. For every guideline of MISRA C++:2023, the compliance matrix (compliance/misra-cpp-2023.yml) records how it is verified (MISRA C:2025 gets compliance/misra-c-2025.yml in the same format):
    • tool: a named clang-tidy or cppcheck check, or a compiler flag, that decides it;
    • review: it is undecidable or no open tool decides it, so it is on the pull-request checklist;
    • commercial checker: decided by the MISRA checker that the safety level adds;
    • not applicable: the construct cannot occur in our code (for example, guidelines about exceptions, which we do not use), with the reason.
  2. Guideline re-categorisation plan. Where our profile is stricter than MISRA (an advisory guideline we treat as required), the matrix says so. We never make a guideline weaker than MISRA classifies it.
  3. Deviations. Every departure from a required guideline has a deviation record: project-wide ones in compliance/misra-cpp-2023-deviations.yml, single places in the repository's own docs/deviations.yml. Mandatory guidelines are never deviated.
  4. Compliance summary. Each release of a high or safety component states, per guideline, whether it is compliant, deviated or not applicable. It is generated from the matrix and the deviation records.

The edition

The matrix is written against MISRA C++:2023 with Technical Corrigendum 1 (TC1:2026). The corrigendum adds no guidelines and is equivalent to MISRA C++:2023, but clarifies many of them, so tool reports can differ from the 2023 text. The licensed copy the matrix was written from is held privately by the maintainer; the matrix records its SHA-256 (licensed_copy_sha256), so any entry can be traced to the exact edition it was checked against. When MISRA publishes a new corrigendum or edition, the matrix is reviewed against it in one pull request that changes the hash.

MISRA C++:2023 targets C++17; our code is C++20 (ADR-0010). The C++20 profile sorts the C++20 features into use, use with rules and forbid, as guidelines KB-CPP20-001 to 058 that extend the edition to C++20. Deviation MD-CPP-001 covers exactly the features the profile allows, under its guidelines; a forbidden feature, a deprecated one, or anything from C++23 or later is a violation of Rule 4.1.1, even where a toolchain's dialect accepts it. The profile page also says how each guideline applies to C++20 constructs.

Reading the matrix

Each guideline has one entry:

Field Meaning
id The guideline number, Rule a.b.c or Dir a.b.c.
kind rule (checkable from the code alone) or directive (needs design or requirements information).
category MISRA's category: mandatory, required or advisory.
decidable Whether an analyser can always answer "compliant?" (yes/no); n/a for directives.
scope tu when one translation unit at a time is enough, system when the whole program is needed.
summary Our own one-line paraphrase (at most 12 words); the standard's text is not reproduced.
applies yes, or no with a reason (for example, the exception guidelines: we build with -fno-exceptions).
our_category The category we enforce: MISRA's or stricter, never weaker. A stricter one is our re-categorisation plan.
verification How it is checked: each item names by (method) and how (the exact flag, check or review step).
deviations The project-wide deviation records that cover part of the guideline, if any.
note Anything a reader needs to apply the guideline to our code.

The verification methods are:

  • compiler: a GCC or Clang flag (with -Werror) whose diagnostic decides the guideline;
  • clang-tidy: a clang-tidy 20 check, with its options where they matter;
  • cppcheck: a cppcheck message id (there is no free MISRA C++ addon; cppcheck's MISRA addon covers MISRA C only);
  • codeql: a query of the pinned CodeQL MISRA C++:2023 pack (codeql/misra-cpp-coding-standards 2.62.0) or the Kokeb C++20 profile pack, run by ci-tools ru-misra on traced host and Cortex-M builds; the how names the query and its tool-validation requirement (ci-tools docs/tool-validation/traceability.md). An entry without partial is a query the validation proved on every seeded form with no recorded anomaly; known anomalies lists the anomaly-log ids that make it partial, and ru-misra lists the findings of a rule with a known false positive for review instead of failing on them;
  • handbook-check: one of the handbook's own implemented checks (checks/source_checks.py for include guards, pragmas and the C++20 profile checks cpp20-profile/..., ci-tools' handbook check for the forbidden patterns);
  • review: the step a reviewer checks on the pull request, used where no free tool decides the guideline;
  • commercial-checker: the MISRA checker the safety level adds, for every guideline no free tool decides;
  • not-applicable: the construct cannot occur in our code, and why.

A tool item marked partial: true finds some violations but cannot prove there are none (an undecidable guideline, or a check narrower than the guideline); such a guideline always also has a review step and the commercial checker. A tool is only listed for a guideline it actually checks. The clang-tidy checks the matrix names are split between two profiles (next section).

checks/misra_matrix.py validates the matrix and the deviations on every pull request: every guideline present exactly once (179), valid categories, our_category never weaker, a verification for every applicable guideline, a reason for every guideline that does not apply, and no deviation of a mandatory guideline. It also keeps the counts below current.

Counts

MISRA C++:2023 with TC1:2026 has 179 guidelines: 4 directives and 175 rules.

MISRA category Directives Rules Total Our category
mandatory 0 5 5 5
required 2 122 124 131
advisory 2 48 50 43
all 4 175 179 179
How it is verified Guidelines
Decided by an open tool (compiler, clang-tidy, cppcheck, handbook check) 93
  of which by compiler 11
  of which by clang-tidy 34
  of which by codeql 73
  of which by handbook-check 2
Review and commercial checker, helped by a partial tool 79
Review and commercial checker only 0
Not applicable to our code 7

A guideline can be decided by more than one tool. Raised above MISRA's category: 7 (Dir 5.7.2, Rule 6.0.3, Rule 9.6.1, Rule 10.2.2, Rule 12.2.1, Rule 13.1.1, Rule 21.6.1). Project-wide deviations: 9 (MD-CPP-001 Rule 4.1.1, MD-CPP-002 Rule 16.6.1, MD-CPP-003 Rule 8.2.5, MD-CPP-004 Rule 8.2.6, MD-CPP-005 Rule 6.7.2, MD-CPP-006 Rule 19.0.2, MD-CPP-007 Rule 21.2.4, MD-CPP-008 Rule 21.6.1, MD-CPP-009 Rule 19.0.3).

clang-tidy profiles

Most of the clang-tidy checks the matrix names are in the org's default configuration (config/.clang-tidy), which every repository at the standard and high levels uses. The rest are in the safety-level profile (config/.clang-tidy-safety): the default plus every check the matrix names that the default leaves off, with the stricter options those guidelines need. The profile is generated by python checks/misra_matrix.py gen from the default and the matrix, and CI fails if it is stale, so the two cannot drift. python checks/misra_matrix.py tidy prints both lists.

Checks the matrix relies on that are on at every level, because they are cheap and fit the code:

Check Guideline Note
hicpp-signed-bitwise Rules 7.0.4, 7.0.5 IgnorePositiveIntegerLiterals: 1U << 3 passes; a uint8_t promoted to int before <<, ~ or | does not, so cast to uint32_t first
readability-uppercase-literal-suffix Rule 5.13.5 NewSuffixes: L;LL;UL;ULL; 0xFFu and 1.0f stay accepted
misc-no-recursion Rule 8.2.10 within one translation unit
misc-static-assert Rule 22.3.1
misc-definitions-in-headers Rule 6.2.4 .ipp counts as a header
misc-unconventional-assign-operator Rule 15.0.2
hicpp-no-assembler Rule 10.4.1
hicpp-multiway-paths-covered Rule 9.4.2 the safety profile adds WarnOnMissingElse for Rule 9.4.1
fuchsia-virtual-inheritance Rules 8.2.1, 13.1.1, 13.1.2
cppcoreguidelines-pro-type-union-access Rule 12.3.1 there are no unions
cppcoreguidelines-pro-type-vararg Rules 8.2.11, 21.10.1 the Log hook takes a plain const char*; host tests and examples that print may turn it off in their own folder
cert-err34-c, cert-env33-c, cert-err52-cpp, cert-flp30-c Rules 21.2.1, 21.2.3, 21.10.2, Dir 0.3.1 through cert-*

Safety level only, because they would fight idioms the standard and high levels accept (public value and error in Result, a deleted copy without a written-out move, byte-buffer arithmetic in tests, test helpers with external linkage) or are style the org does not use elsewhere: cppcoreguidelines-pro-bounds-array-to-pointer-decay, cppcoreguidelines-pro-bounds-pointer-arithmetic, cppcoreguidelines-special-member-functions, misc-non-private-member-variables-in-classes, misc-use-anonymous-namespace, misc-use-internal-linkage and the google-* checks (build-namespaces, default-arguments, explicit-constructor, global-names-in-headers, readability-casting, runtime-int, runtime-operator).

Include guards (Rule 19.2.1) are decided by the handbook's own source check, not by llvm-header-guard, whose names are derived from the path and differ from the convention in KB-CPP-019.

What open tools can and cannot prove

clang-tidy, cppcheck and the compilers decide a large part of MISRA and CERT, but not all of it: some guidelines are undecidable in general, and some decidable ones are only implemented by commercial checkers (Cppcheck Premium, Helix QAC, Parasoft C/C++test, Polyspace and others). The matrix never claims a guideline is checked by a tool that does not check it. At the safety level a commercial checker runs on every release, under the licence of the organisation qualifying the component, and its report becomes part of the evidence package.

The MISRA and CERT documents are copyrighted. The handbook cites guideline numbers, categories and analysis attributes with our own one-line summaries; it does not reproduce headlines, rationale, examples or tables, and the standard itself is never committed to any repository. Contributors working at the safety level need their own licensed copies of the standards.