Agent skill · trailofbits
modern-cpp
Guides C++ code toward modern idioms (C++20/23/26). Use when writing new C++ code, modernizing legacy patterns, or working on security-critical C++. Replaces raw pointers with smart pointers, SFINAE with concepts, printf with std::print, error codes with std::expected.
What it needs
About 5k tokens when loaded.
What this skill does
Modern 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::makeunique, std::makeshared Eliminates leaks, double-free Raw owning pointers std::uniqueptr, std::sharedptr 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 staticcast<int>(x) Explicit intent, auditable #define constants constexpr variables Scoped, typed, debuggable SFINAE / enableif 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::scopedlock Exception-safe, no deadlocks std::thread std::jthread Auto-join, stop token support assert() macro contractassert (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 Feature Tiers Features are ranked by practical usability today, not by standard version. …
How to use it
Reference it in AdaL, Claude Code, Cursor or any coding agent — nothing to install:
@skills trailofbits/modern-cpp