Skip to content

Commit

Permalink
doc: document nullptr comparisons in style guide
Browse files Browse the repository at this point in the history
This documents existing practices.

PR-URL: #23805
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
  • Loading branch information
addaleax authored and targos committed Nov 1, 2018
1 parent 5c35d0d commit 49b32af
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CPP_STYLE_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* [Memory Management](#memory-management)
* [Memory allocation](#memory-allocation)
* [Use `nullptr` instead of `NULL` or `0`](#use-nullptr-instead-of-null-or-0)
* [Use explicit pointer comparisons](#use-explicit-pointer-comparisons)
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
* [Avoid non-const references](#avoid-non-const-references)
* [Others](#others)
Expand Down Expand Up @@ -195,6 +196,12 @@ class FancyContainer {

Further reading in the [C++ Core Guidelines][ES.47].

### Use explicit pointer comparisons

Use explicit comparisons to `nullptr` when testing pointers, i.e.
`if (foo == nullptr)` instead of `if (foo)` and
`foo != nullptr` instead of `!foo`.

### Ownership and Smart Pointers

* [R.20]: Use `std::unique_ptr` or `std::shared_ptr` to represent ownership
Expand Down

0 comments on commit 49b32af

Please sign in to comment.