[SERVER-75815] Add [[gsl::Pointer]] attribute to class StringData Created: 06/Apr/23  Updated: 29/Oct/23  Resolved: 07/Apr/23

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 7.0.0-rc0

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Matt Broadstone
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Sprint: Server Serverless 2023-04-17
Participants:

 Description   

The presence of this attribute allows the compiler to catch dangling references.

std::string_view has this annotation. we should follow suit.

"This ensures that constructing a StringPiece (StringData in our case) from a temporary (xvalue)
std::string will produce a compiler warning (error for us). And it
matches the annotation libc++ does for std::string_view."

https://bugs.chromium.org/p/chromium/issues/detail?id=1282468

class [[gsl::Pointer]] StringData {
...
};

https://godbolt.org/z/Kdoec79ar



 Comments   
Comment by Githook User [ 07/Apr/23 ]

Author:

{'name': 'Matt Broadstone', 'email': 'mbroadst@mongodb.com', 'username': 'mbroadst'}

Message: SERVER-75815 Add gsl::Pointer attribute to StringData
Branch: master
https://github.com/mongodb/mongo/commit/92f0dcde7e594247e153327ba538e55c74b83589

Comment by Billy Donahue [ 06/Apr/23 ]

should be behind a compiler-selective macro as gcc doesn't know about this attribute and annoyingly complains [-Wattributes] about unknown attributes instead of just ignoring them like it's required to.

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