[SERVER-41071] convert all appearances of NULL in C++ code to nullptr Created: 09/May/19  Updated: 29/Oct/23  Resolved: 17/Jun/19

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: 4.3 Required
Fix Version/s: 4.3.1

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: A. Jesse Jiryu Davis
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Problem/Incident
Backwards Compatibility: Fully Compatible
Sprint: Dev Tools 2019-06-17
Participants:
Linked BF Score: 100

 Description   

C's NULL has weaker type safety than C++11's nullptr. It's convertible to nullptr_t, but also to integer types (emitting a warning, but still).

2011 was a while ago. NULL is unnecessary vocabulary, and should be easy to globally replace.



 Comments   
Comment by Ratika Gandhi [ 18/Jul/19 ]

acm, should this be backported to 4.2?

Comment by Githook User [ 19/Jun/19 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-41071 Fix Windows build after nullptr change
Branch: master
https://github.com/mongodb/mongo/commit/145f4d0e1e738833f4ea1d0cd8e825088f885995

Comment by Githook User [ 17/Jun/19 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-41071 Replace NULL with nullptr
Branch: master
https://github.com/10gen/mongo-enterprise-modules/commit/cbeea1525f62e05298eec94aaf8fcad8ecffc7ef

Comment by Githook User [ 17/Jun/19 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-41071 Replace more NULLs with nullptr
Branch: master
https://github.com/mongodb/mongo/commit/6633498e9cecbeeb85b10ccbd6492f117d94d07a

Comment by Githook User [ 14/Jun/19 ]

Author:

{'name': 'A. Jesse Jiryu Davis', 'email': 'jesse@mongodb.com', 'username': 'ajdavis'}

Message: SERVER-41071 Replace NULL and 0 with nullptr
Branch: master
https://github.com/mongodb/mongo/commit/47b380f03e8898f4706ff01fa2be64dfb72e0dba

Comment by A. Jesse Jiryu Davis [ 14/Jun/19 ]

Yes, clang-modernize is now part of clang-tidy and it has an option for nullptr.

# Create compile_commands.json
python buildscripts/scons.py  \
    --variables-files=etc/scons/mongodbtoolchain_v3_clang.vars \
    MONGO_VERSION='0.0.0' MONGO_GIT_HASH='unknown' \
    --ssl --dbg generated-sources compiledb
 
# Strip src/third_party from compile_commands.json
python -c "import json; json.dump([c for c in json.load(open('compile_commands.json')) if not c['file'].startswith('src/third_party')], open('compile_commands.json', 'w'))"
 
# Looks for compile_commands.json in current dir. '-*' disables default checks.
# The -header-filter arg ensures all non-system headers are fixed, and ignores third_party
python3 /opt/mongodbtoolchain/v3/share/clang/run-clang-tidy.py -clang-tidy-binary=/opt/mongodbtoolchain/v3/bin/clang-tidy -clang-apply-replacements-binary=/opt/mongodbtoolchain/v3/bin/clang-apply-replacements -checks='-*,modernize-use-nullptr' -header-filter='src/mongo/.*' -fix

Comment by Andrew Morrow (Inactive) [ 09/May/19 ]

Could we use clang-modernize to do this for us? Does it have such a converter?

Generated at Thu Feb 08 04:56:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.