[SERVER-68210] idl generates suspicious std::move's for _dbName Created: 21/Jul/22  Updated: 05/Dec/22

Status: Open
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Eric Milkie Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Operating System: ALL
Participants:

 Description   

In buildscripts/idl/idl/generator.py, we generate special initializer code for _dbName members such that it uses an already moved-from nss variable.  For examples:

ListIndexes::ListIndexes(const NamespaceStringOrUUID nssOrUUID)
    : _nssOrUUID(std::move(nssOrUUID)),
      _dbName(nssOrUUID.uuid() ? nssOrUUID.dbname() : nssOrUUID.nss().get().db().toString()),
      _hasDbName(true) {}

ShardsvrDropCollectionIfUUIDNotMatchingRequest::ShardsvrDropCollectionIfUUIDNotMatchingRequest(
    const NamespaceString nss,
    mongo::UUID expectedCollectionUUID)
    : _nss(std::move(nss)),
      _expectedCollectionUUID(std::move(expectedCollectionUUID)),
      _dbName(nss.db().toString()),
      _hasExpectedCollectionUUID(true),
      _hasDbName(true) {}

While this code may technically work okay, it would be nicer to initialize _dbName with _nss instead of nss so that static analysis checkers aren't flagging it.



 Comments   
Comment by Billy Donahue [ 21/Jul/22 ]

The const on the nss arguments make the std::move useless.
The nss argument is not moved from. It can't be. But this is not performant or very logically clean. The const should be removed from nss, and further references to nss should be changed to _nss instead.

Generated at Thu Feb 08 06:10:12 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.