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 <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
  • Loading branch information
addaleax authored and targos committed Oct 26, 2018
1 parent 48807f5 commit 50d54f5
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CPP_STYLE_GUIDE.md
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 50d54f5

Please sign in to comment.