You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
move ctor for strict_not_null should be removed #1246
In commit 9ff6e19 (issue #743) in 2018 strict_not_null was introduced. The interface was almost identical to the one of not_null, but the constructor is explicit.
Later in commit 6b23937 in 2020 the move ctor for not_null was removed, but the move constructor for strict_not_null was not removed.
In my opinion the move constructor for strict_not_null should be removed as it was done with the move constructor for not_null. This aligns the interfaces of both classes to be the same. And it removes code that looks like it moves but instead copies, which is at least surprising.
Are you wanting the user-defined strict_not_null(strict_not_null&& other) to be = delete;? or to just be removed? The former has already been discussed (and rejected) in #842. The latter is not really a behavior change.
And it removes code that looks like it moves but instead copies, which is at least surprising.
Whether you remove it or keep it, a copy will happen. This behavior is intentional and is already the case with gsl::not_null. https://godbolt.org/z/svh1f8hdd
This aligns the interfaces of both classes to be the same.
I'm happy to accept a PR that makes the interfaces match.
That being said, I interpret the description of #743 as "We introduced gsl::strict_not_null to help customers upgrade". This type is not something specified by the core guidelines (as far as I can tell). Perhaps at this point the best decision is to remove gsl::strict_not_null in the next major GSL release (w/ gsl::dyn_array)?
That being said, I interpret the description of #743 as "We introduced gsl::strict_not_null to help customers upgrade". This type is not something specified by the core guidelines (as far as I can tell). Perhaps at this point the best decision is to remove gsl::strict_not_null in the next major GSL release (w/ gsl::dyn_array)?
I read 743 as the opposite. It says "using explicit constructor is very beneficial for new code, since it encourages better API design and make null checks intentional." So I think strict_not_null was added to be used in new code, because forcing the explicit behavior onto not_null would break most legacy code using it. So my preference would be to keep it. If it was removed, my recommendation would be to add an option to add or remove explicit from not_null with a macro one way or another, as mentioned in #699 (comment) (GSL_NON_EXPLICIT_NOT_NULL_CTOR)
I am not sure anymore. The move ctor here checks for is_nothrow_copy_constructible, so maybe there is a good reason to keep it? Yet the different interfaces are strange.
I'm leaning towards flipping #1247 and adding that interface to gsl::not_null. Basically, I want a defaulted move constructor on gsl::not_null to be noexcept(is_nothrow_copy_constructible).
This is certainly a contrived example, but I don't think we want to restrict (as in std::terminate()) users from throwing in their copy constructors.
I guess this makes sense. While the number of users may be limited, as a library it seems better to be flexible here. However, this is an issue with all other ctors, and I think the move ctor for strict_not_null should still be removed.
For reference, the patch to fix the other ctors noexcept clauses would be:
Activity
beinhaerter commentedon May 26, 2026
Thanks to maflcko who brought my attention to it in #1245.
maflcko commentedon May 26, 2026
(off-topic: Heh, I still prefer #1238 to make it movable, but this seems possibly controversial and also off-topic here)
on-topic: I agree that removing it is the least confusing and most self-consistent fix for now.
carsonRadtke commentedon May 27, 2026
Are you wanting the user-defined
strict_not_null(strict_not_null&& other)to be= delete;? or to just be removed? The former has already been discussed (and rejected) in #842. The latter is not really a behavior change.Whether you remove it or keep it, a copy will happen. This behavior is intentional and is already the case with
gsl::not_null. https://godbolt.org/z/svh1f8hddI'm happy to accept a PR that makes the interfaces match.
That being said, I interpret the description of #743 as "We introduced
gsl::strict_not_nullto help customers upgrade". This type is not something specified by the core guidelines (as far as I can tell). Perhaps at this point the best decision is to removegsl::strict_not_nullin the next major GSL release (w/gsl::dyn_array)?WDYT? Gabriel Dos Reis (@gdr-at-ms)
carsonRadtke commentedon May 27, 2026
Edit: I just saw your PR. "just be removed" is the answer.
maflcko commentedon May 28, 2026
I read 743 as the opposite. It says "using explicit constructor is very beneficial for new code, since it encourages better API design and make null checks intentional." So I think
strict_not_nullwas added to be used in new code, because forcing the explicit behavior ontonot_nullwould break most legacy code using it. So my preference would be to keep it. If it was removed, my recommendation would be to add an option to add or removeexplicitfromnot_nullwith a macro one way or another, as mentioned in #699 (comment) (GSL_NON_EXPLICIT_NOT_NULL_CTOR)carsonRadtke commentedon May 28, 2026
Fair enough. GitHub code search for "gsl::strict_not_null" has a fair amount of hits, so deleting it is probably not the right call.
beinhaerter commentedon May 29, 2026
I am not sure anymore. The move ctor here checks for is_nothrow_copy_constructible, so maybe there is a good reason to keep it? Yet the different interfaces are strange.
maflcko commentedon May 29, 2026
I think this is just an artifact of running clang-tidy on the codebase (d69e578)
carsonRadtke commentedon May 29, 2026
I'm leaning towards flipping #1247 and adding that interface to
gsl::not_null. Basically, I want a defaulted move constructor ongsl::not_nullto benoexcept(is_nothrow_copy_constructible).Motivating example: https://godbolt.org/z/4qbeE8YzK (notice the switch on line 58).
This is certainly a contrived example, but I don't think we want to restrict (as in
std::terminate()) users from throwing in their copy constructors.I'd like to hear other thoughts if there are any. This is a topic I will bring up at the next internal GSL sync (tentatively mid-July).
maflcko commentedon Jun 2, 2026
I guess this makes sense. While the number of users may be limited, as a library it seems better to be flexible here. However, this is an issue with all other ctors, and I think the move ctor for strict_not_null should still be removed.
For reference, the patch to fix the other ctors noexcept clauses would be:
show patch