Skip to content

gsl::strict_not_null: C.66 Make move ctor noexcept#1245

Closed
maflcko wants to merge 1 commit into
microsoft:mainfrom
maflcko:2605-strict-move-noexcept
Closed

gsl::strict_not_null: C.66 Make move ctor noexcept#1245
maflcko wants to merge 1 commit into
microsoft:mainfrom
maflcko:2605-strict-move-noexcept

Conversation

@maflcko
Copy link
Copy Markdown
Contributor

@maflcko maflcko commented May 26, 2026

The strict_not_null move ctor actually calls the copy ctor, as explained in the comment added in commit d69e578. The comment also says that a custom pointer type copy ctor "could in theory throw exceptions". However, I don't think that such a smart pointer type should exist in practise.

Also, it violates C66, see https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c66-make-move-operations-noexcept

So just use a noexcept for all types.

@carsonRadtke
Copy link
Copy Markdown
Member

However, I don't think that such a smart pointer type should exist in practise.

boost::intrusive_ptr exists and has a potentially throwing copy constructor.

Also, it violates C66

It does. I think this is going to be a case where the GSL implementation is not going to conform to the guidelines because a specific decision was made to implement the gsl::strict_not_null move constructor with copy constructor semantics (which also violates C.64: A move operation should move and leave its source in a valid state). If you think that was not a good decision, I'm happy to discuss it, but for now I think we should leave the constructor as potentially throwing.

WDYT? @gdr-at-ms

@maflcko
Copy link
Copy Markdown
Contributor Author

maflcko commented May 26, 2026

However, I don't think that such a smart pointer type should exist in practise.

boost::intrusive_ptr exists and has a potentially throwing copy constructor.

Ok, I see. I think GSL being flexible and fully supporting such a throwing copy ctor seems reason enough to close this. After all, everyone who marks their copy ctors as noexcept won't see any difference here anyway.

Closing for now, but happy to re-open, if GSL decides to follow C.66

@maflcko maflcko closed this May 26, 2026
@maflcko maflcko deleted the 2605-strict-move-noexcept branch May 26, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants