{"skill":{"slug":"cpp","displayName":"C++","summary":"Avoid common C++ mistakes — memory leaks, dangling references, undefined behavior, and ownership confusion.","description":"---\nname: C++\nslug: cpp\nversion: 1.0.1\ndescription: Write safe C++ avoiding memory leaks, dangling pointers, undefined behavior, and ownership confusion.\nmetadata: {\"clawdbot\":{\"emoji\":\"⚡\",\"requires\":{\"bins\":[\"g++\"]},\"os\":[\"linux\",\"darwin\",\"win32\"]}}\n---\n\n## Quick Reference\n\n| Topic | File |\n|-------|------|\n| RAII, smart pointers, new/delete | `memory.md` |\n| Raw pointers, references, nullptr | `pointers.md` |\n| Rule of 3/5/0, inheritance, virtual | `classes.md` |\n| Containers, iterators, algorithms | `stl.md` |\n| Templates, SFINAE, concepts | `templates.md` |\n| Threads, mutex, atomics | `concurrency.md` |\n| C++11/14/17/20, move semantics | `modern.md` |\n| Undefined behavior traps | `ub.md` |\n\n## Critical Rules\n\n- Raw `new` without `delete` leaks — use `std::unique_ptr` or `std::make_unique`\n- Returning reference to local — undefined behavior, object destroyed on return\n- `==` for C-strings compares pointers — use `std::string` or `strcmp()`\n- Signed integer overflow is UB — not wrap-around like unsigned\n- Virtual destructor required in base class — otherwise derived destructor skipped\n- `std::move` doesn't move — it casts to rvalue, enabling move semantics\n- Moved-from object valid but unspecified — don't use without reassigning\n- Data race on non-atomic is UB — use `std::mutex` or `std::atomic`\n- `vector<bool>` is not a real container — returns proxy, use `deque<bool>`\n- `map[key]` inserts default if missing — use `find()` or `contains()` to check\n- Braced init `{}` prevents narrowing — `int x{3.5}` errors, `int x(3.5)` truncates\n- Iterator invalidation on `push_back` — vector may relocate, invalidating iterators\n- `string_view` doesn't own data — underlying string must outlive the view\n","tags":{"latest":"1.0.1"},"stats":{"comments":0,"downloads":1918,"installsAllTime":10,"installsCurrent":10,"stars":2,"versions":2},"createdAt":1770679844751,"updatedAt":1778486238781},"latestVersion":{"version":"1.0.1","createdAt":1771103249943,"changelog":"Initial release","license":null},"metadata":{"setup":[],"os":["linux","darwin","win32"],"systems":null},"owner":{"handle":"ivangdavila","userId":"s178jdk12x4qj3gs2se3etxf3h83h7ft","displayName":"Iván","image":"https://avatars.githubusercontent.com/u/81719670?v=4"},"moderation":null}