-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: add gsl::not_null to get compile time / run time pointer guarantees #5595
refactor: add gsl::not_null to get compile time / run time pointer guarantees #5595
Conversation
I think |
Well, we could change this to just be assert(false) then instead of calling std::terminate |
Will we have in this case any error message in console (without debugger) such as "pointer X at file.cpp:NNN is null" also same as with assert? If so it's fine then |
Please take a look at this further set of changes and LMK what you think? it uses an early implementation of c++20's std::source_location that I think should be low cost; provides output now like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK if it works as described
Btw, looks like magic for location of call
src/gsl/assert.h
Outdated
{ | ||
#if defined(GSL_MSVC_USE_STL_NOEXCEPTION_WORKAROUND) | ||
(*gsl::details::get_terminate_handler())(); | ||
#else | ||
std::cout << "ERROR: error detected null not_null detected at " << loc.file_name() << ":" << loc.line() << ":" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Std::cerr I think should be, also std::endl to flush buffer
As I checked, at least
main.cpp:
So, std::terminate(), abort() and assert() behave are very similar in gdb and std::terminate seems completely fine. Probably I got confused by |
This pull request has conflicts, please rebase. |
Signed-off-by: pasta <[email protected]>
Signed-off-by: pasta <[email protected]>
c849e71
to
634ca5e
Compare
Co-authored-by: UdjinM6 <[email protected]>
Co-authored-by: UdjinM6 <[email protected]>
…ptr' into introduce-not-null-ptr
let's maybe have both cout and LogPrintf? UdjinM6@4eb326c |
It should not be stdout, but stderr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK
src/gsl/assert.h
Outdated
#else | ||
std::ostringstream s; | ||
s << "ERROR: error detected null not_null detected at " << loc.file_name() << ":" << loc.line() << ":" | ||
<< loc.column() << ":" << loc.function_name() << "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to use std::endl instead to ensure that it actually flushes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, we could do 3d69147. I doubt it would make any difference but 🤷♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-ACK
LGTM |
Issue being fixed or feature implemented
Current implementation relies either on asserts or sometimes checks then returning a special value; In the case of asserts (or no assert where we use the value without checks) it'd be better to make it explicit to function caller that the ptr must be not_null; otherwise gsl::not_null will call terminate.
See https://github.com/microsoft/GSL/blob/main/docs/headers.md#user-content-H-pointers-not_null and https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rf-nullptr
I'm interested in a conceptual review; specifically on if this is beneficial over just converting these ptrs to be a reference?
What was done?
Partial implementation on using gsl::not_null in dash code
How Has This Been Tested?
Building
Breaking Changes
None
Checklist:
Go over all the following points, and put an
x
in all the boxes that apply.