Pular para o conteúdo
Skillpedia
Código em geral8,0 mil · #12684

modern-cpp

O que ela faz

Orienta o código C++ rumo aos padrões modernos, do C++20 ao C++26, com foco em segurança. É para desenvolvedores que escrevem código C++ novo ou atualizam código antigo.

Quando usar

  • ✓Quando um desenvolvedor escreve novas funções, classes ou bibliotecas em C++.
  • ✓Quando um desenvolvedor quer código C++ antigo atualizado para padrões modernos.
  • ✓Quando um desenvolvedor trabalha com C++ crítico para segurança e quer padrões mais seguros.

Link da skill

https://github.com/trailofbits/skills/blob/main/plugins/modern-cpp/skills/modern-cpp/SKILL.md

Copie e cole na sua IA (Claude, ChatGPT ou Cursor) pedindo para seguir as instruções.

Como usar

O jeito mais fácil: copie a mensagem e cole na sua IA. Ela lê a skill e segue as instruções.

Mensagem pronta para colar

Use esta skill para me ajudar: https://github.com/trailofbits/skills/blob/main/plugins/modern-cpp/skills/modern-cpp/SKILL.md Leia o arquivo SKILL.md desse link e siga as instruções dele na minha tarefa.
Quer que a sua IA encontre skills como esta sozinha?Instale o MCP grátis do Skillpedia: uma linha, e ela pesquisa entre 15.000+ skills antes de cada tarefa.Instalar em 1 minuto →

Exemplo do que pedir para a IA

“Atualize esta classe C++ antiga para usar ponteiros inteligentes e tratamento de erros moderno.”

5 skills novas por semana. 1 minuto de leitura.

Como funciona

A skill substitui padrões arriscados, como new e delete diretos, arrays de C, printf e casts no estilo C, por alternativas modernas mais seguras, e explica por que cada mudança ajuda. Ela respeita qualquer padrão mais antigo que um projeto exija.

Conteúdo técnico (SKILL.md original)

Texto original do autor, em inglês, direto do GitHub.

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::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_FAST for ~0.3% overhead bounds-checking
  • Sanitizers in CI — ASan + UBSan as minimum; TSan for concurrent code
  • Warning flags
Perguntas frequentes

O que ela substitui?

Substitui padrões como new e delete diretos, arrays de C, printf e casts no estilo C por opções modernas mais seguras.

Cobre CMake?

Não. A configuração do sistema de build está fora do escopo.

E se meu projeto precisar de um padrão mais antigo?

A skill respeita isso e se mantém no padrão que o projeto exige.

Detalhes

Descrição original do autor

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.

repo: trailofbits/skills

Popularidade

Estrelas no GitHub
8,0 mil
Posição no ranking
#12684
Licença
CC-BY-SA-4.0
Atualizada em
02/11/2026

Essa skill é útil?

0

Entre para votar.

Comentários

  • …

Mais skills deste repositório

Skills parecidas