modern-cpp Skill
✓ VerifiziertLeitet die C++-Entwicklung mit Fokus auf Sicherheit und Memory Safety zu modernen Idiomen unter Verwendung der Standards C++20, C++23 und C++26 an.
- GitHub Stars
- 8.136
- Dateien
- 7
- Letzter Commit
- 11. Nov. 2026
- Lizenz
- CC-BY-SA-4.0
- Erlaubte Tools
- —
Was macht der modern-cpp Skill?
modern-cpp ist ein Agent Skill. Leitet die C++-Entwicklung mit Fokus auf Sicherheit und Memory Safety zu modernen Idiomen unter Verwendung der Standards C++20, C++23 und C++26 an.
Zusammenfassung erzeugt aus der SKILL.md des Skills.
Über den modern-cpp skill
Das Schreiben von sicherem, modernem C++-Code unter Verwendung der neuesten Standards ist die Hauptfunktion dieses Skills. Er unterstützt Entwickler beim Übergang von Legacy-Mustern zu modernen Idiomen, wie sie in C++20, C++23 und C++26 zu finden sind. Wenn ein Agent diesen Skill lädt, kann er Anleitungen dazu geben, unsichere Praktiken wie Raw Pointer oder C-Style Casts durch sicherere Alternativen wie Smart Pointer, std::span und static_cast zu ersetzen.
Dieses Tool ist besonders nützlich für alle, die neue Libraries bauen, bestehende Codebases modernisieren oder an sicherheitskritischer Software arbeiten. Es liefert konkrete Tipps zur Nutzung spezifischer Features wie Concepts als Ersatz für SFINAE, std::expected für das Error Handling und std::print für typsichere Ausgaben. Über die Syntax hinaus bietet es Unterstützung bei Compiler-Hardening-Flags und dem Einsatz von Sanitizern in der Continuous Integration, um Schwachstellen zu reduzieren. Der Fokus liegt strikt auf C++ und deckt keine Build-Systeme wie CMake oder Meson ab.
Was ein agent damit machen kann
- 1Legacy C++ Code modernisierenEin Agent kann dabei helfen, alte Muster in moderne Standards zu migrieren, indem er Ersatzmöglichkeiten für manuelles Memory Management und C-Style Arrays vorschlägt.
- 2Codesicherheit verbessernEntwickler können dies nutzen, um sicherheitsorientierte Patterns zu implementieren, die gängige Schwachstellenklassen eliminieren.
- 3Compiler Hardening konfigurierenDer Skill liefert spezifische Flags, um die Sicherheit deiner Builds durch Hardening des Compilers und der Libraries zu erhöhen.
Geschrieben basierend auf dem SKILL.md des skills. Jeder use case wurde gegen ein zitat daraus geprüft.
So installierst du den modern-cpp Skill
Jeder Befehl kopiert den Skill-Ordner in das Skills-Verzeichnis des Clients. Starte den Client neu oder beginne eine neue Session, um ihn zu laden.Den modern-cpp Skill in Plugin installieren
/plugin marketplace add trailofbits/skills /plugin install modern-cpp@trailofbits
Den modern-cpp Skill in Claude Code installieren
~/.claude/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.claude/skills/modern-cppDen modern-cpp Skill in Claude Code (project) installieren
.claude/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp .claude/skills/modern-cppDen modern-cpp Skill in Codex installieren
~/.agents/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.agents/skills/modern-cppDen modern-cpp Skill in Gemini CLI installieren
~/.gemini/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.gemini/skills/modern-cppDen modern-cpp Skill in Claude.ai installieren
npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp modern-cpp && zip -r modern-cpp.zip modern-cpp # claude.ai → Customize → Skills → + → Create skill → Upload a skill → modern-cpp.zip
Automatisierte Checks
Geluften am 14. Nov. 2026Vollständiger Bericht →Hat unsere automatischen Prüfungen bestanden. Das ist kein Sicherheitsaudit: Lesen Sie die Skripte, bevor ein Agent sie ausführt. Wie die Checks funktionieren
- Source Repository verknüpft und erreichbartrailofbits/skills/plugins/modern-cpp/skills/modern-cpp is public and reachablegithub.com/trailofbits/skills/tree/HEAD/plugins/modern-cpp/s ↗Bestanden
- Open Source Lizenz (OSI)CC-BY-SA-4.0 is not OSI-approvedspdx.org/licenses/CC-BY-SA-4.0.html ↗Befund
- Commit oder Release im letzten JahrLast commit 2026-11-11github.com/trailofbits/skills/commits ↗Bestanden
- Keine Download-und-Ausführen-Muster oder Zugangsdatendiebstahl in SkriptenNo scripts in the skill folderBestanden
- Keine versteckten Anweisungen in SKILL.mdNo override phrases, safeguard switches, credential requests or hidden charactersgithub.com/trailofbits/skills/blob/HEAD/plugins/modern-cpp/s ↗Bestanden
- Vorab erlaubte Tools sind eingeschränktNo pre-approved tools; the agent asks before using onegithub.com/trailofbits/skills/blob/HEAD/plugins/modern-cpp/s ↗Bestanden
SKILL.md
Auf GitHub ansehenModern C++
Guide for writing modern C++ using C++20, C++23, and C++26 idioms. Focuses on patterns that eliminate vulnerability classes and reduce boilerplate, with a security emphasis from Trail of Bits.
When to Use This Skill
- Writing new C++ functions, classes, or libraries
- Modernizing existing C++ code (pre-C++20 patterns)
- Choosing between legacy and modern approaches
- Working on security-critical or safety-sensitive C++
- Reviewing C++ code for modern idiom adoption
When NOT to Use This Skill
- User explicitly requires older standard: Respect constraints (embedded, legacy ABI)
- Pure C code: This skill is C++-specific
- Build system questions: CMake, Meson, Bazel configuration is out of scope
- Non-C++ projects: Mixed codebases where C++ isn't primary
Anti-Patterns to Avoid
| Avoid | Use Instead | Why |
|---|---|---|
new/delete |
std::make_unique, std::make_shared |
Eliminates leaks, double-free |
| Raw owning pointers | std::unique_ptr, std::shared_ptr |
RAII ownership semantics |
C arrays (int arr[N]) |
std::array<int, N> |
Bounds-aware, value semantics |
| Pointer + length params | std::span<T> |
Non-owning, bounds-checkable |
printf / sprintf |
std::format, std::print |
Type-safe, no buffer overflow |
C-style casts (int)x |
static_cast<int>(x) |
Explicit intent, auditable |
#define constants |
constexpr variables |
Scoped, typed, debuggable |
SFINAE / enable_if |
Concepts + requires |
Readable constraints and errors |
| Error codes + out params | std::expected<T, E> |
Composable, type-safe errors |
union |
std::variant |
Type-safe, no silent UB |
Raw mutex.lock()/unlock() |
std::scoped_lock |
Exception-safe, no deadlocks |
std::thread |
std::jthread |
Auto-join, stop token support |
assert() macro |
contract_assert (C++26) |
Visible to tooling, configurable |
| Manual CRTP | Deducing this (C++23) |
Simpler, no template boilerplate |
| Macro code generation | Reflection (C++26) | Zero-overhead, composable |
See anti-patterns.md for the full table (30+ patterns).
Decision Tree
What are you doing?
|
+-- Writing new C++ code?
| +-- Use modern idioms by default (C++20/23)
| +-- Choose the newest standard your compiler supports
| +-- See Feature Tiers below
|
+-- Modernizing existing code?
| +-- Start with Tier 1 (C++20/23) replacements
| +-- Prioritize by security impact (memory > types > style)
| +-- See anti-patterns.md for the migration table
|
+-- Security-critical code?
| +-- Enable compiler hardening flags (see below)
| +-- Enable hardened libc++ mode
| +-- Run sanitizers in CI
| +-- See safe-idioms.md and compiler-hardening.md
|
+-- Using C++26 features?
+-- Reflection: YES, plan for it (GCC 16+)
+-- Contracts: cautiously, for new API boundaries
+-- std::execution: wait for ecosystem maturity
+-- See cpp26-features.md
Feature Tiers
Features are ranked by practical usability today, not by standard version.
Tier 1: Use Today (C++20/23, solid compiler support)
| Feature | Replaces | Standard |
|---|---|---|
Concepts + requires |
SFINAE, enable_if |
C++20 |
| Ranges + views | Raw iterator loops | C++20 |
std::span<T> |
Pointer + length | C++20 |
std::format |
sprintf, iostream chains |
C++20 |
Three-way comparison <=> |
Manual comparison operators | C++20 |
std::jthread |
std::thread + manual join |
C++20 |
| Designated initializers | Positional struct init | C++20 |
std::expected<T,E> |
Error codes, exceptions at boundaries | C++23 |
std::print / std::println |
printf, std::cout << |
C++23 |
Deducing this |
CRTP, const/non-const duplication | C++23 |
std::flat_map |
std::map for read-heavy use |
C++23 |
Monadic std::optional |
Nested if-checks on optionals | C++23 |
See cpp20-features.md and cpp23-features.md.
Tier 2: Deploy Now (no standard bump needed)
These improve safety without changing your C++ standard version:
- Compiler hardening flags —
-D_FORTIFY_SOURCE=3,-fstack-protector-strong,-ftrivial-auto-var-init=zero - Hardened libc++ —
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FASTfor ~0.3% overhead bounds-checking - Sanitizers in CI — ASan + UBSan as minimum; TSan for concurrent code
- Warning flags —
-Wall -Wextra -Wpedantic -Werror
Tier 3: Plan For (C++26, worth restructuring around)
Reflection is the single most transformative C++26 feature. It eliminates:
- Serialization boilerplate (one generic function replaces per-struct
to_json) - Code generators (protobuf codegen, Qt MOC)
- Macro-based registration and enum-to-string hacks
GCC 16 (April 2026) has reflection merged. Plan new code to benefit from it.
Tier 4: Watch (C++26, needs maturation)
- Contracts (
pre/post/contract_assert) — Better thanassert(), but no virtual function support and limited compiler support. Adopt cautiously for new API boundaries. - std::execution (senders/receivers) — Powerful async framework, but steep learning curve, no scheduler ships with it, and poor documentation. Wait for ecosystem maturity.
See cpp26-features.md.
Compiler Hardening Quick Reference
Essential Flags (GCC + Clang)
-Wall -Wextra -Wpedantic -Werror
-D_FORTIFY_SOURCE=3
-fstack-protector-strong
-fstack-clash-protection
-ftrivial-auto-var-init=zero
-fPIE -pie
-Wl,-z,relro,-z,now
Clang-Specific
-Wunsafe-buffer-usage
Hardened libc++ (Clang/libc++ only)
-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_FAST
Google deployed this across Chrome and their server fleet: ~0.3% overhead, 1000+ bugs found, 30% reduction in production segfaults.
See compiler-hardening.md for the full guide.
Rationalizations to Reject
| Rationalization | Why It's Wrong |
|---|---|
| "It compiles without warnings" | Warnings depend on which flags you enable. Add -Wall -Wextra -Wpedantic. |
| "ASan is too slow for production" | Use GWP-ASan for sampling-based production detection (~0% overhead). |
| "We only use safe containers" | Iterator invalidation and unchecked optional access are still exploitable. |
| "Smart pointers are slower" | std::unique_ptr has zero overhead vs raw pointers. Measure before claiming. |
| "Our code doesn't have memory bugs" | Google found 1000+ bugs when enabling hardened libc++. So did everyone else. |
| "C++26 features aren't available yet" | C++20/23 features are. Hardening flags work on any standard. Start there. |
| "Modern C++ is harder to read" | std::expected is more readable than checking error codes across 5 out-params. |
Best Practices Checklist
- Use smart pointers for ownership, raw pointers only for non-owning observation
- Prefer
std::spanover pointer + length for function parameters - Use
std::expectedfor functions that can fail with typed errors - Constrain templates with concepts, not SFINAE
- Enable compiler hardening flags and hardened libc++ in all builds
- Run ASan + UBSan in CI; add TSan for concurrent code
- Use
constexpr/constevalwhere possible (UB-free by design) - Mark functions
[[nodiscard]]when ignoring the return value is likely a bug - Prefer value semantics; use
std::variantoverunion,enum classoverenum - Initialize all variables at declaration
Read Next
- anti-patterns.md — Full legacy-to-modern migration table (30+ patterns)
- cpp20-features.md — Concepts, ranges, span, format, coroutines
- cpp23-features.md — expected, print, deducing this, flat_map
- cpp26-features.md — Reflection, contracts, memory safety improvements
- compiler-hardening.md — Flags, sanitizers, hardened libc++
- safe-idioms.md — Security patterns by vulnerability class
Dateien in diesem Skill
7modern-cpp Skill-Fragen
Wie installiere ich den modern-cpp Skill in Claude Code?
Führe npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.claude/skills/modern-cpp aus. Claude Code lädt Skills aus ~/.claude/skills (alle Projekte) oder .claude/skills (ein Projekt) und nutzt einen Skill, wenn seine Beschreibung zur Aufgabe passt.
Welche Clients können den modern-cpp Skill nutzen?
Jeder Client, der das Agent Skills-Format liest: Claude Code, Codex, Gemini CLI und claude.ai (als ZIP hochladen). Skripte im Skill laufen nur dort, wo der Client Codeausführung erlaubt.
Wie kann ich die Sicherheit in meinem C++-Code verbessern, ohne den Standard zu ändern?
Du kannst Compiler-Hardening-Flags wie -D_FORTIFY_SOURCE=3 verwenden, den hardened libc++ mode aktivieren und Sanitizer wie ASan und UBSan in deiner CI-Pipeline laufen lassen.
Was ist der beste Weg, um Fehler in modernem C++ zu behandeln?
Anstatt Error Codes und Out-Parameter zu verwenden, solltest du std::expected für komponierbare, typsichere Fehler nutzen.
Ist std::unique_ptr langsamer als ein Raw Pointer?
Nein, std::unique_ptr hat im Vergleich zu Raw Pointern keinen Overhead.