modern-cpp skill
✓ 인증됨C++20, C++23, C++26 표준을 사용하여 보안과 메모리 안전성에 중점을 둔 현대적인 C++ 개발 방식을 안내합니다.
- GitHub 스타
- 8,136
- 파일
- 7
- 마지막 커밋
- 2026년 11월 11일
- 라이선스
- CC-BY-SA-4.0
- 허용된 도구
- —
modern-cpp skill은 무엇을 하나요?
modern-cpp은(는) agent skill입니다. C++20, C++23, C++26 표준을 사용하여 보안과 메모리 안전성에 중점을 둔 현대적인 C++ 개발 방식을 안내합니다.
skill의 SKILL.md에서 생성된 요약입니다.
modern-cpp skill 정보
최신 표준을 사용하여 안전하고 현대적인 C++ 코드를 작성하는 것이 이 SKILL의 주요 기능입니다. 개발자가 레거시 패턴에서 C++20, C++23, C++26의 현대적인 관용구로 전환할 수 있도록 지원합니다. 에이전트가 이 SKILL을 로드하면 raw pointer나 C-style cast와 같은 안전하지 않은 관행을 smart pointer, std::span, static_cast와 같은 더 안전한 대안으로 교체하는 방법을 안내할 수 있습니다.
이 도구는 새로운 라이브러리를 구축하거나, 기존 코드베이스를 현대화하거나, 보안이 중요한 소프트웨어를 개발하는 경우에 특히 유용합니다. SFINAE를 대체하는 concepts, 에러 처리를 위한 std::expected, 타입 안전한 출력을 위한 std::print와 같은 특정 기능의 사용법에 대해 실행 가능한 조언을 제공합니다. 단순한 문법을 넘어, 취약점을 줄이기 위한 컴파일러 하드닝 플래그 사용법과 지속적 통합(CI) 환경에서의 sanitizer 활용법에 대한 가이드도 제공합니다. 이 도구는 C++에만 집중하며 CMake 또는 Meson과 같은 빌드 시스템은 다루지 않습니다.
agent가 수행할 수 있는 작업
- 1레거시 C++ 코드 현대화에이전트가 수동 메모리 관리와 C-style array를 대체할 방법을 제안하여 오래된 패턴을 현대적 표준으로 마이그레이션하도록 도울 수 있습니다.
- 2코드 보안 개선개발자는 일반적인 취약점 유형을 제거하는 보안 중심 패턴을 구현하는 데 이 도구를 사용할 수 있습니다.
- 3컴파일러 하드닝 설정컴파일러 및 라이브러리 하드닝을 통해 빌드 보안을 강화할 수 있는 특정 플래그를 제공합니다.
skill의 SKILL.md를 기반으로 작성되었습니다. 모든 사용 사례는 해당 문서의 인용구와 대조 확인되었습니다.
modern-cpp skill 설치 방법
각 명령은 skill 폴더를 클라이언트의 skills 디렉터리에 복사합니다. 클라이언트를 재시작하거나 새 세션을 시작하여 로드하세요.플러그인에 modern-cpp skill 설치
/plugin marketplace add trailofbits/skills /plugin install modern-cpp@trailofbits
Claude Code에 modern-cpp skill 설치
~/.claude/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.claude/skills/modern-cppClaude Code (project)에 modern-cpp skill 설치
.claude/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp .claude/skills/modern-cppCodex에 modern-cpp skill 설치
~/.agents/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.agents/skills/modern-cppGemini CLI에 modern-cpp skill 설치
~/.gemini/skills/modern-cpp/SKILL.md
$ npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.gemini/skills/modern-cppClaude.ai에 modern-cpp skill 설치
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
자동 검사
2026년 11월 14일에 실행됨전체 보고서 →자동 검사를 통과했습니다. 보안 감사는 아닙니다. 에이전트가 실행하기 전에 스크립트를 읽어 보세요. 검사 방식
- 소스 저장소 연결 및 접근 가능trailofbits/skills/plugins/modern-cpp/skills/modern-cpp is public and reachablegithub.com/trailofbits/skills/tree/HEAD/plugins/modern-cpp/s ↗통과
- 오픈 소스 라이선스 (OSI)CC-BY-SA-4.0 is not OSI-approvedspdx.org/licenses/CC-BY-SA-4.0.html ↗결함 발견
- 최근 1년 내 커밋 또는 릴리스Last commit 2026-11-11github.com/trailofbits/skills/commits ↗통과
- 스크립트에 다운로드 후 실행이나 자격 증명 탈취가 없음No scripts in the skill folder통과
- SKILL.md에 숨겨진 지침 없음No override phrases, safeguard switches, credential requests or hidden charactersgithub.com/trailofbits/skills/blob/HEAD/plugins/modern-cpp/s ↗통과
- 사전 허용 도구가 제한됨No pre-approved tools; the agent asks before using onegithub.com/trailofbits/skills/blob/HEAD/plugins/modern-cpp/s ↗통과
SKILL.md
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_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
이 스킬의 파일
7modern-cpp skill 질문
Claude Code에 modern-cpp skill을 어떻게 설치하나요?
npx degit trailofbits/skills/plugins/modern-cpp/skills/modern-cpp ~/.claude/skills/modern-cpp를 실행합니다. Claude Code는 ~/.claude/skills(모든 프로젝트) 또는 .claude/skills(한 프로젝트)에서 skills를 로드하며, 설명이 작업과 일치할 때 skill을 사용합니다.
modern-cpp skill을 사용할 수 있는 클라이언트는 무엇인가요?
Agent Skills 형식을 읽는 모든 클라이언트(Claude Code, Codex, Gemini CLI, claude.ai(ZIP으로 업로드))가 사용할 수 있습니다. skill 내 스크립트는 클라이언트가 코드 실행을 허용하는 경우에만 실행됩니다.
표준을 변경하지 않고 C++ 코드의 보안을 개선하려면 어떻게 해야 하나요?
-D_FORTIFY_SOURCE=3와 같은 컴파일러 하드닝 플래그를 사용하거나, 하드닝된 libc++ 모드를 활성화하고, CI 파이프라인에서 ASan 및 UBSan과 같은 sanitizer를 실행할 수 있습니다.
현대적인 C++에서 에러를 처리하는 가장 좋은 방법은 무엇인가요?
에러 코드나 out 파라미터를 사용하는 대신, 조합 가능하고 타입 안전한 에러 처리를 위해 std::expected를 사용해야 합니다.
std::unique_ptr가 raw pointer보다 느린가요?
아니요, std::unique_ptr는 raw pointer와 비교했을 때 오버헤드가 전혀 없습니다.