Skip to content
Skills Library
Programming · Review & audit

static-analysis

/static-analysis

Use when hardening C/C++ code quality with clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, integrating into CI, or working with compile_commands.json.

Licence
Apache-2.0
Last repository change
28.09.2026

Assessment and security

100/ 100Class: good
Format25 / 25
Frontmatter with name and description, valid name, description up to 1,024 characters, name matching the folder.
Discoverability25 / 25
Description explains when to use the skill, has a reasonable length and uses third person.
Content35 / 35
At least 150 words and at most 500 lines, headings, step lists, examples or code.
Hygiene15 / 15
No placeholders such as TODO, no Windows paths, with a licence.
Riskno signals detected in the scan
Files in this package
3
Scripts
0
HTML comments
0
URLs in SKILL.md
0
Deprecation

No signals detected. Repository changed on 28.09.2026, without references to retired models or APIs.

Licence

Apache-2.0, otwarta: można używać i zmieniać, z zachowaniem licencji i informacji o zmianach.

What it does and when to use it

Use when hardening C/C++ code quality with clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, integrating into CI, or working with compile_commands.json.

Original author description

Use when hardening C/C++ code quality with clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, integrating into CI, or working with compile_commands.json.

How it works

  1. Contract
  2. Inputs
  3. Procedure
  4. Failure and recovery
  5. Output
Original SKILL.md headings · 143 lines, 701 words
SKILL.md preview
---
name: static-analysis
description: 'Use when hardening C/C++ code quality with clang-tidy, cppcheck, or scan-build, interpreting check categories, suppressing false positives, integrating into CI, or working with compile_commands.json.'
disable-model-invocation: true
---

# Static analysis

Select, run, and triage C/C++ static analysis: clang-tidy, cppcheck, and scan-build. Grounded against LLVM/Clang 23.1.0 and cppcheck 2.21.0.

## Contract

| Field | Bound contract |
|---|---|
| Trigger | The task runs or configures clang-tidy, cppcheck, or scan-build, interprets check categories, suppresses false positives, generates `compile_commands.json`, or wires static analysis into CI. |
| Authority | Reversible local: writes only `.clang-tidy`, suppression comments, source files (through `-fix`), and analysis reports; rollback is version control. No remote mutation. |
| Side effect | `clang-tidy -fix` edits source files in place; analyzers read the compilation database. |
| Done | The analyzer runs over the intended translation units and findings are triaged into fixed, suppressed with reason, or reported. |

## Inputs

- A C/C++ project (required) and its build system.
- A compilation database (required for clang-tidy): `compile_commands.json`.
- Check policy (optional): which categories to enable and which warnings are errors.

## Procedure

1. Generate `compile_commands.json`. Done when: the database covers the sources to analyze.

```bash
cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
ln -s build/compile_commands.json .

# Make-based trees
bear -- make
# or: pip install compiledb && compiledb make
```

2. Run clang-tidy. Done when: diagnostics cover the intended files.

```bash
clang-tidy src/foo.c -- -std=c23 -I include/
run-clang-tidy -p build/ -j"$(nproc)"
clang-tidy -checks='bugprone-*,modernize-*,performance-*' src/foo.cpp
clang-tidy -checks='modernize-use-nullptr' -fix src/foo.cpp
```

3. Pick check categories by goal. Done when: the enabled set matches the stated goal.

| Goal | Categories |
|---|---|
| Find real bugs | `bugprone-*`, `clang-analyzer-*` |
| Modernize C++ | `modernize-*` |
| C++ Core Guidelines | `cppcoreguidelines-*` |
| Performance | `performance-*` |
| Security hardening | `cert-*`, `hicpp-*` |
| Readability and style | `readability-*` |

4. Commit a `.clang-tidy` at the project root so every run uses the same policy. Done when: the config file parses and `clang-tidy` picks it up.

```yaml
Checks: >
  bugprone-*,
  modernize-*,
  performance-*,
  -modernize-use-trailing-return-type,
  -bugprone-easily-swappable-parameters
WarningsAsErrors: 'bugprone-*,clang-analyzer-*'
HeaderFilterRegex: '^(src|include)/.*'
CheckOptions:
  - key: modernize-loop-convert.MinConfidence
    value: reasonable
  - key: readability-identifier-naming.VariableCase
    value: camelCase
```

5. Suppress false positives with NOLINT comments; clang-tidy has no attribute-based suppression. Done when: each suppression names its check and carries a reason.

```cpp
int result = riskyOp();  // NOLINT(bugprone-signed-char-misuse) - hardware register

// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
constexpr int BUFFER_SIZE = 4096;

// NOLINTBEGIN(readability-*)
...legacy block...
// NOLINTEND(readability-*)
```

Exclude third-party trees with `HeaderFilterRegex` rather than NOLINT.

6. Run cppcheck as a second, independent analyzer. Done when: cppcheck runs with an explicit enable set and exit code.

```bash
cppcheck --enable=warning,performance,portability \
         --suppress=missingIncludeSystem \
         --error-exitcode=1 \
         --std=c23 \
         src/

cppcheck --project=build/compile_commands.json
cppcheck --xml --xml-version=2 src/ 2> cppcheck-report.xml
```

`--enable` values: `warning` (undefined behavior, bad practice), `performance`, `portability`, `information`, or `all`.

7. Run scan-build for path-sensitive analysis. It wraps a build and drives the Clang static analyzer, which tracks execution paths across functions: use-after-free, dead stores, null dereferences on complex paths. Done when: the HTML report is generated and triaged.

```bash
scan-build make
scan-build -o /tmp/scan-out cmake --build build/
scan-view /tmp/scan-out/*/

# Enable a specific checker; list all with clang -cc1 -analyzer-checker-help
scan-build -enable-checker security.insecureAPI.gets make
```

8. Wire analysis into CI as a gate. Done when: the CI job fails on new warnings.

```yaml
- name: Static analysis
  run: |
    cmake -S . -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
    run-clang-tidy -p build -j"$(nproc)" -warnings-as-errors '*'

- name: cppcheck
  run: |
    cppcheck --enable=warning,performance \
             --suppress=missingIncludeSystem \
             --error-exitcode=1 \
             src/
```

For per-check details see `references/clang-tidy-checks.md`.

## Failure and recovery

- clang-tidy finds no compilation database: generate `compile_commands.json` first; without it flags and include paths are guesses.
- Fix-its break the build: revert the file; apply `-fix` per check, not across the whole suite at once.
- Warning storm hides real bugs: enable one category at a time, fix or suppress, then widen.
- NOLINT on a third-party file: exclude the path with `HeaderFilterRegex` instead.
- scan-build reports nothing: it only sees what the wrapped build compiles; force a full rebuild with `make -B` or a clean build directory.
- cppcheck `missingIncludeSystem` noise: the flag suppresses it; deeper fixes need `--includes-file` or `-I` flags.

## Output

A `.clang-tidy` or cppcheck configuration encoding the agreed check policy, a triaged findings list (fixed, suppressed with reason, or open), and a CI step that gates on new warnings.
Files in this package (3)
  • SKILL.md 6 KB
  • agents/openai.yaml 1 KB
  • references/clang-tidy-checks.md 3 KB

Versions

RepositoryScoreLicence
This page · OutlineDriven/outline-driven-development100Apache-2.0
ramottamado/skills100MIT
gmh5225/awesome-llvm-security100MIT
mohitmishra786/low-level-dev-skills100MIT
Tyler-R-Kendrick/agent-skills95MIT

Database snapshot: 13.11.2026 · package version eede3a335ef2 (SHA-256 digest of the entire package)

Downloads in the last 30 days: 0 · ranking

Report a problem with this skill: harmful content, incorrect descriptions or an author’s removal request.

Similar skills

  • 100cpp-static-analysis
    Run and interpret the static-analysis tool stack for this repository's C++ code: clang-format, clang-tidy, clang static analyzer (scan-build), cppcheck, include-what-you-use (IWYU), and the sanitizer-instrumented dev build. Use when the user asks about static analysis, lint,…
  • 100cpp-quality
    C++ static analysis and formatting tooling: clang-tidy, clang-format, cppcheck, include-what-you-use (IWYU), and CI integration patterns. USE WHEN: user mentions "clang-tidy", "clang-format", "cppcheck", "iwyu", "include-what-you-use", ".clang-tidy", ".clang-format", "C++ static…
  • 100clang
    Clang/LLVM compiler skill for C/C++ projects. Use when working with clang or clang++ for diagnostics, sanitizer instrumentation, optimization remarks, static analysis with clang-tidy, LTO via lld, or when migrating from GCC to Clang. Activates on queries about clang flags,…
  • 100clang
    Use when a C or C++ build uses clang and needs diagnostics, optimization remarks, clang-tidy, ThinLTO with lld, LLVM PGO, or a GCC-to-Clang migration. Not for LLVM IR work: use llvm.
  • 90cpp-review
    Reviewing C++ code - what to flag, and what the compiler, clang-tidy and sanitizers already flag for you USE WHEN: you are reviewing, critiquing or auditing existing C++ code - a "code review", a "review" of a .cpp/.hpp/.cc/.h file, a diff, a PR or a pull request; deciding what…
  • 100sota-c-cpp
    State-of-the-art C and C++ engineering rules that Claude applies when writing or auditing C/C++. Covers modern idioms (RAII, value semantics, smart pointers, C++23), memory safety (lifetimes, bounds, sanitizers, hardening flags), undefined behavior, security (SEI CERT C/C++,…

Feedback and reports

Your message goes to Bartosz Sokoliński. An email address is needed only for a reply. See the privacy policy.