基于 C++ Core Guidelines 提供现代、安全、惯用的 C++ 编码规范建议
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "cpp-coding-standards" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/cpp-coding-standards/SKILL.md 2. 保存为 ~/.claude/skills/cpp-coding-standards/SKILL.md 3. 装好后重载技能,告诉我可以用了
请根据 C++ Core Guidelines 审查下面这段 C++ 代码,指出不安全、过时或不符合现代 C++ 惯例的地方,并给出修改建议与改进后的代码。
返回逐条问题清单、对应规范依据,以及一版更安全规范的重构代码。
把这段旧版 C++ 代码重构为现代 C++ 风格,优先使用 RAII、智能指针、const correctness、范围 for 和标准库设施,并解释每项修改原因。
输出重构后的现代 C++ 代码,并说明如何提升安全性、可读性与可维护性。
基于 C++ Core Guidelines,为我的团队整理一份简明的 C++ 编码规范,覆盖命名、资源管理、异常处理、接口设计和代码审查检查项。
生成一份结构化团队规范文档,可直接用于开发约定或代码审查清单。
Comprehensive coding standards for modern C++ (C++17/20/23) derived from the C++ Core Guidelines. Enforces type safety, resource safety, immutability, and clarity.
enum vs enum class, raw pointer vs smart pointer)These themes recur across the entire guidelines and form the foundation:
const/constexpr; mutability is the exception| Rule | Summary |
|---|---|
| P.1 | Express ideas directly in code |
| P.3 | Express intent |
| P.4 | Ideally, a program should be statically type safe |
| P.5 | Prefer compile-time checking to run-time checking |
| P.8 | Don't leak any resources |
| P.10 | Prefer immutable data to mutable data |
| I.1 | Make interfaces explicit |
| I.2 | Avoid non-const global variables |
| I.4 | Make interfaces precisely and strongly typed |
| I.11 | Never transfer ownership by a raw pointer or reference |
| I.23 | Keep the number of function arguments low |
// P.10 + I.4: Immutable, strongly typed interface
struct Temperature {
double kelvin;
};
Temperature boil(const Temperature& water);
// Weak interface: unclear ownership, unclear units
double boil(double* temp);
// Non-const global variable
int g_counter = 0; // I.2 violation
| Rule | Summary |
|---|---|
| F.1 | Package meaningful operations as carefully named functions |
| F.2 | A function should perform a single logical operation |
| F.3 | Keep functions short and simple |
| F.4 | If a function might be evaluated at compile time, declare it constexpr |
| F.6 | If your function must not throw, declare it noexcept |
| F.8 | Prefer pure functions |
| F.16 | For "in" parameters, pass cheaply-copied types by value and others by const& |
| F.20 | For "out" values, prefer return values to output parameters |
| F.21 | To return multiple "out" values, prefer returning a struct |
| F.43 | Never return a pointer or reference to a local object |
// F.16: Cheap types by value, others by const&
void print(int x); // cheap: by value
void analyze(const std::string& data); // expensive: by const&
void transform(std::string s); // sink: by value (will move)
// F.20 + F.21: Return values, not output parameters
struct ParseResult {
std::string token;
int position;
};
ParseResult parse(std::string_view input); // GOOD: return struct
// BAD: output parameters
void parse(std::string_view input,
std::string& token, int& pos); // avoid this
// F.4 + F.8: Pure, constexpr where possible
constexpr int factorial(int n) noexcept {
…
帮助开发者为代码代理配置性能优化、安全防护与研究优先工作流。
提供数据库迁移、回滚与零停机发布的最佳实践指导,适用于多种 ORM 与 SQL 数据库。
通过双评审智能体对结果进行对抗式校验,提升输出发布前的可靠性
帮助你掌握地道 Rust 模式、所有权与并发实践,编写安全高性能应用。
基于 C++ Core Guidelines 编写、审查并重构更安全现代的 C++ 代码。
为 Claude Code 会话提供系统化校验流程,帮助检查结果正确性与质量。
依据C++核心指南辅助编写、审查与重构更现代安全的C++代码。
用于编写、修复与诊断 C++ 测试,并配置覆盖率与消毒器。
帮助开发者编写和审查符合 Hermes VM 垃圾回收安全规范的 C++ 代码
用于编写和修复 C++ 测试,并配置 GoogleTest、CTest 与诊断问题。
提供适用于 TypeScript、JavaScript、React 与 Node.js 的通用编码规范与最佳实践。
为 Spring Boot 与 Quarkus 服务生成并统一应用 Java 编码规范。