Mention stream-operator dead code in DCHECK docs
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}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
b4c0dad800
commit
e18c24349f
@ -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
|
||||
|
Reference in New Issue
Block a user