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
shared_ptr Derived types cannot be implicitly cast to the share_ptr Base types with gsl::not_null #1187
Describe the bug
When I try to change function A to return a gsl::not_null<std::shared_ptr> instead of std::shared_ptr, it causes problems in function B that returns the result of function A as a std::shared_ptr
To Reproduce
#include<gsl>
#include<memory>classBase
{
};
classDerived : publicBase
{
};
gsl::not_null<std::shared_ptr<Derived>> A()
{
return std::make_shared<Derived>();
}
std::shared_ptr<Base> B()
{
// this fails to compile after the result of A was changed to a not_nullreturnA();
}
// your repro here: ...
Expected behavior
I expect the code above to compile and work exactly the same with or without the gsl::not_null
Spec (please complete the following information):
OS: Windows
Microsoft (R) C/C++ Optimizing Compiler Version 19.28.29335 for x64
All C++ versions
Additional context
Changing the implicit conversion operator:
Activity
carsonRadtke commentedon Jan 27, 2025
Thanks for reporting this issue!
We will look into improving the experience here - the decision on how to proceed will likely be made at the internal maintainer's sync.
carsonRadtke commentedon Feb 28, 2025
Maintainer's call: Forward this issue to CppCoreGuidelines folks.