e76d0ad892
CI / Test (macos-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 18.x, bun) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 18.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 20.x, bun) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 20.x, yarn) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (macos-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 22.x, bun) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (ubuntu-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, npm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, pnpm) (push) Has been cancelled
CI / Test (windows-latest, Node 22.x, yarn) (push) Has been cancelled
CI / Validate Components (push) Has been cancelled
CI / Python Tests (push) Has been cancelled
CI / Security Scan (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / Lint (push) Has been cancelled
2.6 KiB
2.6 KiB
inclusion, fileMatchPattern, description
| inclusion | fileMatchPattern | description |
|---|---|---|
| fileMatch | *.cpp,*.hpp,*.h,*.cc,*.cxx | C++ coding standards, RAII, smart pointers, and modern C++ patterns. |
C++ Patterns
This file extends the common patterns with C++ specific content.
Modern C++ (C++17/20/23)
- Prefer modern C++ features over C-style constructs
- Use
autowhen the type is obvious from context - Use
constexprfor compile-time constants - Use structured bindings:
auto [key, value] = map_entry;
RAII (Resource Acquisition Is Initialization)
Tie resource lifetime to object lifetime — no manual new/delete:
class FileHandle {
public:
explicit FileHandle(const std::string& path) : file_(std::fopen(path.c_str(), "r")) {}
~FileHandle() { if (file_) std::fclose(file_); }
FileHandle(const FileHandle&) = delete;
FileHandle& operator=(const FileHandle&) = delete;
private:
std::FILE* file_;
};
Smart Pointers
- Use
std::unique_ptrfor exclusive ownership - Use
std::shared_ptronly when shared ownership is truly needed - Use
std::make_unique/std::make_sharedover rawnew
Rule of Five/Zero
- Rule of Zero: Prefer classes that need no custom destructor, copy/move constructors, or assignments
- Rule of Five: If you define any of destructor/copy-ctor/copy-assign/move-ctor/move-assign, define all five
Value Semantics & Error Handling
- Pass small/trivial types by value, large types by
const& - Return by value (rely on RVO/NRVO)
- Use
std::optionalfor values that may not exist - Use
std::expected(C++23) or result types for expected failures
Memory Safety
- Never use raw
new/delete— use smart pointers - Never use C-style arrays — use
std::arrayorstd::vector - Use
std::stringoverchar* - Use
.at()for bounds-checked access when safety matters - Never use
strcpy,strcat,sprintf
Formatting & Static Analysis
clang-format -i <file>
clang-tidy --checks='*' src/*.cpp
cppcheck --enable=all src/
Testing
Use GoogleTest (gtest/gmock) with CMake/CTest:
cmake --build build && ctest --test-dir build --output-on-failure
Always run tests with sanitizers in CI:
cmake -DCMAKE_CXX_FLAGS="-fsanitize=address,undefined" ..
Naming Conventions
- Types/Classes:
PascalCase - Functions/Methods:
snake_caseorcamelCase(follow project convention) - Constants:
kPascalCaseorUPPER_SNAKE_CASE - Namespaces:
lowercase
Reference
See agents: cpp-reviewer, cpp-build-resolver for C++ review and build error resolution.
See skill: cpp-coding-standards for comprehensive C++ guidelines.