Skip to content

Commit 49b32af

Browse files
addaleaxtargos
authored andcommitted
doc: document nullptr comparisons in style guide
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]>
1 parent 5c35d0d commit 49b32af

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

CPP_STYLE_GUIDE.md

+7
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
* [Memory Management](#memory-management)
1919
* [Memory allocation](#memory-allocation)
2020
* [Use `nullptr` instead of `NULL` or `0`](#use-nullptr-instead-of-null-or-0)
21+
* [Use explicit pointer comparisons](#use-explicit-pointer-comparisons)
2122
* [Ownership and Smart Pointers](#ownership-and-smart-pointers)
2223
* [Avoid non-const references](#avoid-non-const-references)
2324
* [Others](#others)
@@ -195,6 +196,12 @@ class FancyContainer {
195196

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

199+
### Use explicit pointer comparisons
200+
201+
Use explicit comparisons to `nullptr` when testing pointers, i.e.
202+
`if (foo == nullptr)` instead of `if (foo)` and
203+
`foo != nullptr` instead of `!foo`.
204+
198205
### Ownership and Smart Pointers
199206

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

0 commit comments

Comments
 (0)