Code review for C++ specifics: ownership first.

Review Ownership First, Style Last

Most code reviews are a performative waste of time, a shallow ritual where senior devs hunt for missing semicolons or inconsistent indentation while the actual logic burns a hole in the heap. I spent years in high-frequency trading watching brilliant engineers pass “clean” reviews, only to have a production outage triggered by a single, overlooked lifetime issue that no linter could catch. If your team treats code review for c++ specifics as a mere stylistic check, you aren’t actually reviewing code; you’re just polishing the brass on a sinking ship.

I’m not here to teach you how to argue about brace placement or variable naming conventions. I want to show you how to look for the structural rot that actually matters: the subtle violations of the object model, the implicit conversions that swallow errors, and the narrow windows of undefined behavior that the compiler is all too happy to exploit. This is about developing an eye for the rules that bite, ensuring that when you finally merge that PR, you aren’t just shipping features, but shipping correctness.

Table of Contents

Hunting the Silent Killers a C Undefined Behavior Checklist

Hunting the Silent Killers a C Undefined Behavior Checklist

When I sit down to review a pull request, I don’t look for style violations; I look for ways the machine is going to lie to you. Your first line of defense should be a rigorous C++ undefined behavior checklist. Start with the basics: integer overflows in signed arithmetic and out-of-bounds access that looks perfectly legal because you’re using raw pointers. If you see a manual `delete` or a custom destructor managing a raw resource, flag it immediately. In a modern codebase, if I don’t see RAII principles in code review being applied to every single resource acquisition, the PR shouldn’t even reach the CI stage.

Next, look at how the code handles lifetime. I’ve spent enough late nights debugging segfaults to know that “it works on my machine” usually means you’ve accidentally accessed a dangling reference that the compiler just hasn’t optimized into oblivion yet. Watch for improper smart pointer usage patterns, specifically `std::shared_ptr` cycles that will silently leak memory until your process hits the OOM killer. Finally, check your concurrency. If I see a shared variable being accessed without an explicit memory barrier or an atomic wrapper, I assume the code is broken.

Enforcing Raii Principles in Code Review to Prevent Leaks

Enforcing Raii Principles in Code Review to Prevent Leaks

If I see a raw `new` or `delete` in a pull request, my first instinct is to reject it. In a modern codebase, manual memory management is almost always a symptom of a developer fighting the language rather than using it. When you’re performing RAII principles in code review, you aren’t just looking for leaks; you’re looking for ownership ambiguity. If a function returns a raw pointer, you have to ask: who owns this? Does it need to be deleted? Is it safe to pass to another thread? If the answer isn’t immediately obvious from the type system, the code is a ticking time bomb.

I focus heavily on smart pointer usage patterns to resolve this ambiguity. A `std::unique_ptr` tells me exactly what the lifecycle looks like—it’s clear, it’s singular, and it’s safe. If I see a `std::shared_ptr` being thrown around like confetti, I get suspicious. Overusing shared ownership is a lazy way to avoid thinking about object lifetimes, and it usually leads to circular dependencies that no amount of debugging will easily solve. Look for the intent behind the pointer, not just the syntax.

The Five-Point Audit: What I Actually Look For

  • Stop obsessing over naming conventions and start hunting for iterator invalidation. If I see a `std::vector::push_back` inside a loop that relies on a previously fetched iterator, I’m flagging it immediately. The compiler isn’t going to save you when that reallocation happens.
  • Check the const-correctness, but specifically for pointer-to-const vs. const-pointer distinctions. It’s not about being pedantic; it’s about ensuring the object model actually protects the state you think is protected. If a method doesn’t modify the logical state, it must be `const`.
  • Audit the exception safety guarantees. I don’t care if the code “works” in the happy path; I want to know what happens to your invariants when an allocation fails halfway through a complex operation. If you aren’t providing at least the basic exception guarantee, you’re just building a house of cards.
  • Watch for implicit conversions that hide expensive or dangerous operations. If a function takes a `std::string` by value instead of `std::string_view` or `const std::string&`, or if a constructor isn’t marked `explicit`, you’re inviting subtle performance drags and logic bugs that are a nightmare to debug in a production trace.
  • Scrutinize the lifetime of captured variables in lambdas. It’s the easiest way to ship a use-after-free. If I see a lambda capturing by reference `[&]` in a context where that lambda might outlive the current scope—like an asynchronous callback—that code is dead on arrival.

The Reviewer's Bottom Line

Stop looking for stylistic consistency; start looking for the semantic gaps where the standard says “undefined” and your logic assumes “defined.”

If a PR contains a raw `new` or `delete` without a damn good reason, it’s a failure of RAII and should be rejected on principle.

Treat every optimization opportunity as a potential trap; if the code relies on a specific side effect that the compiler isn’t forced to preserve, it isn’t correct code.

The Reality of the Review

Code review in C++ isn’t about catching a missing semicolon or a typo; the compiler has already handled that. It is about scrutinizing the intent against the actual mechanics of the language. You need to be looking for the subtle ways a developer might have accidentally bypassed RAII, the places where a pointer might outlive its owner, or where a seemingly innocuous optimization might turn a piece of logic into undefined behavior. If you aren’t actively hunting for edge cases in the object model and the potential for memory mismanagement, you aren’t really reviewing the code—you’re just proofreading it.

Ultimately, mastering C++ requires a shift in mindset from “does this work?” to “how can the compiler prove me wrong?” It is a discipline of skepticism. When you sit down for your next review, don’t just look at the logic on the screen; look for the ghosts in the machine that appear only when the flags change or the hardware shifts. C++ is a powerful, unforgiving tool, but it rewards those who respect its complexity. Stop treating the language like a black box and start treating it like the precise mathematical contract it actually is.

About Ruaridh Kensington-Oyelaran

C++ rewards people who know what the compiler is allowed to do. I write about the rules that bite, the ones nobody mentions until you have already shipped the bug.

More From Author

Sorting stability and why it matters.

When Two Items Tie, Someone Has to Decide, and It Should Be You