[SERVER-54032] checked_cast improvements Created: 25/Jan/21  Updated: 23/Mar/23

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

Type: Improvement Priority: Major - P3
Reporter: Billy Donahue Assignee: Backlog - Service Architecture
Resolution: Unresolved Votes: 0
Labels: re-triaged-ticket, servicearch-wfbf-day
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Assigned Teams:
Service Arch
Participants:

 Description   
  • Unconditionally return the result of a static_cast, not dynamic_cast.

Only do the dynamic_cast in debug builds as a look-see. We don't want interferences from dynamic_cast's capability to do side-casts, producing code that only compiles in debug builds.

  • Add a sfinae check on checked_cast so it only participates in overload resolution when a static_cast would succeed.

References:

Realm's checked_cast import:
https://github.com/realm/realm-core/pull/4331/files#diff-e5bfb8e3654dd2c72e622d276e0cde39f22951a14d18c28631676808c51bc8ce

Possible improvement on that from using stdx::is_detected.
https://gcc.godbolt.org/z/dj57bT

Suggested by Mathias in a server-servicearch Slack thread.
https://mongodb.slack.com/archives/CMLKU7Y1M/p1611141797007100



 Comments   
Comment by Lauren Lewis (Inactive) [ 18/Mar/22 ]

We haven’t heard back from you for some time, so we're going to close this ticket. If this is still an issue for you, please provide additional information and we will reopen the ticket.

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