.kiro/steering/cpp-patterns.md
This file extends the common patterns with C++ specific content.
auto when the type is obvious from contextconstexpr for compile-time constantsauto [key, value] = map_entry;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_;
};
std::unique_ptr for exclusive ownershipstd::shared_ptr only when shared ownership is truly neededstd::make_unique / std::make_shared over raw newconst&std::optional for values that may not existstd::expected (C++23) or result types for expected failuresnew/delete — use smart pointersstd::array or std::vectorstd::string over char*.at() for bounds-checked access when safety mattersstrcpy, strcat, sprintfclang-format -i <file>
clang-tidy --checks='*' src/*.cpp
cppcheck --enable=all src/
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" ..
PascalCasesnake_case or camelCase (follow project convention)kPascalCase or UPPER_SNAKE_CASElowercaseSee agents: cpp-reviewer, cpp-build-resolver for C++ review and build error resolution.
See skill: cpp-coding-standards for comprehensive C++ guidelines.