Code Review Checklist

Comprehensive checklist for reviewing modern C++ code

Contract (API Design)

  • Function parameters use appropriate types (const ref for read-only, value for small/cheap types)
  • Template functions use concepts to document requirements
  • Fallible functions return expected/optional instead of throwing or output parameters
  • Function names clearly indicate what they do (especially mutating functions)
  • Noexcept is specified where appropriate

Ownership & Resources

  • No raw new/delete - use smart pointers or containers
  • unique_ptr used for exclusive ownership, shared_ptr for shared
  • std::move used correctly (not on return values, not on const objects)
  • RAII - resources acquired in constructors, released in destructors
  • Weak pointers used to break potential circular references

Type Safety

  • auto used appropriately (not when type clarity is important)
  • No C-style casts - use static_cast, dynamic_cast, etc.
  • nullptr used instead of NULL or 0
  • enum class used instead of plain enum
  • std::optional used instead of sentinel values

Modern C++ Features

  • Range-based for loops preferred over index loops
  • Structured bindings used for pairs/tuples
  • std::string_view for read-only string parameters
  • Lambdas capture appropriately (by value or reference)
  • if constexpr used instead of SFINAE where possible

Performance

  • Pass by const reference for large read-only objects
  • Reserve capacity for vectors when size is known
  • emplace_back preferred over push_back for constructing
  • No unnecessary copies (check for missing std::move)
  • Small string optimization considered

Error Handling

  • Exceptions used for exceptional circumstances only
  • std::expected or std::optional for expected failures
  • No exception specifications (except noexcept)
  • Error messages are actionable and informative

Security

  • No buffer overruns (use std::span or at())
  • Integer overflow considered
  • No use of unsafe functions (strcpy, sprintf, etc.)
  • Sensitive data properly cleared