[SERVER-51240] Add clang tidy rules to prevent const return by value and (in declarations) const pass by value Created: 30/Sep/20  Updated: 29/Oct/23  Resolved: 05/Oct/20

Status: Closed
Project: Core Server
Component/s: Internal Code
Affects Version/s: None
Fix Version/s: 4.9.0

Type: Improvement Priority: Major - P3
Reporter: Vishnu Kaushik Assignee: Benety Goh
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to SERVER-57428 Coverity analysis defect 120147: Pars... Closed
related to SERVER-53580 restore const qualifiers to arguments... Closed
is related to SERVER-27984 Add clang-tidy run in addition to lint Closed
is related to SERVER-49800 add use-after-move rule to clang-tidy... Closed
is related to SERVER-50165 parallelize clang-tidy task Closed
Backwards Compatibility: Fully Compatible
Sprint: Execution Team 2020-10-19
Participants:

 Description   

There are parts of the codebase that suffer fromĀ const return by value and const pass by value.

These can be caught by clang tidy, and we would like to add rules to do so. This and this are two clang tidy rules that could help us do so.

However, there is one issue to watch out for:
A const qualifier is often used on a pass-by-value param in the implementation file (here's an example). This is a readability enhancement. The reader of the function will now know that the function will not touch modify that param. This usage of the const qualifier shouldn't be flagged.



 Comments   
Comment by Githook User [ 04/Oct/20 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-51240 add readability-avoid-const-params-in-decls to clang-tidy rules
Branch: master
https://github.com/mongodb/mongo/commit/f9b27f554543471cf405a0448e90f934651dc626

Comment by Githook User [ 04/Oct/20 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-51240 fix readability-avoid-const-params-in-decls in tests
Branch: master
https://github.com/mongodb/mongo/commit/9ba166c429b07ef3cfb4d8553d39564150844196

Comment by Githook User [ 02/Oct/20 ]

Author:

{'name': 'Benety Goh', 'email': 'benety@mongodb.com', 'username': 'benety'}

Message: SERVER-51240 add readability-const-return-type to clang-tidy rules
Branch: master
https://github.com/mongodb/mongo/commit/b02bba04f8379a0ef6bc76ba475f1b063a6e1323

Generated at Thu Feb 08 05:24:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.