Skip to content

Commit

Permalink
Mention stream-operator dead code in DCHECK docs
Browse files Browse the repository at this point in the history
This adds explicit mentions for dead-code elimination of Foo() in
DCHECK() << Foo(); to c++-dos-and-donts.md, which may look like it's
"outside" the DCHECK() itself.

Bug: None
Change-Id: Ief157f2d77c66742a15ccbac9517dd3dfd7e6dda
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3018441
Reviewed-by: danakj <danakj@chromium.org>
Commit-Queue: Peter Boström <pbos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#900108}
  • Loading branch information
pbos authored and Chromium LUCI CQ committed Jul 9, 2021
1 parent b4c0dad commit e18c243
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions styleguide/c++/c++-dos-and-donts.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,12 @@ void ExpensiveStuff() { ... } // No problem.
// The ExpensiveStuff() call will not happen in official release builds. No need
// to use checks for DCHECK_IS_ON() anywhere.
DCHECK(ExpensiveStuff());

std::string ExpensiveDebugMessage() { ... } // No problem.

// Calls in stream operators are also dead code in official release builds (not
// called with the result discarded). This is fine.
DCHECK(...) << ExpensiveDebugMessage();
```
This code will probably do expensive things that are not needed in official
Expand Down

0 comments on commit e18c243

Please sign in to comment.