[Bug analyzer/125223] Poor UX when analyzer reports on issues inside C++ std types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125223 --- Comment #3 from Jonathan Wakely --- (In reply to David Malcolm from comment #0) > A C++ developer presumably thinks of this as a std::unique_ptr "being > nullptr", Similarly, nullptr is a null pointer constant, i.e. a thing that can be used to initialize a pointer. But it's not a pointer and it's not a thing you can dereference. const int* p = nullptr; // p is a null pointer value, and it compares equal to nullptr, // but it is wrong to say that p *is* nullptr. *p; // dereferences a null pointer value, does not dereference nullptr. For an analogy, I can initialize an int with a floating-point-literal: int i = 1.5; but it's not correct to say that i *is* 1.5, or that ++i adds 1 to 1.5, because 1.5 is just a constant used to initialize the int, not what the int *is*.
[Bug analyzer/125223] Poor UX when analyzer reports on issues inside C++ std types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125223 --- Comment #2 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #1) > Aside: I don't like the use of "NULL" in those diagnostics. That is a macro > with the value 0 (or maybe 0L or 0LL or similar), not a pointer. That's for C++. In C the macro might expand to a pointer, if NULL is defined as (void*)0, but you still can't dereference that because you can't dereference a void pointer. So it's still a category error even for C. The code would not even compile if you tried to dereference "NULL". What the analyzer is detecting is dereferencing a null pointer. https://cigix.me/c23#6.3.2.3.p3 https://eel.is/c++draft/basic.compound#3.sentence-8
[Bug analyzer/125223] Poor UX when analyzer reports on issues inside C++ std types
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125223 --- Comment #1 from Jonathan Wakely --- The GDB printers just give you a string representation of the object's value, I don't think that's what you want here. Maybe don't descend into any member functions of types in namespace std if those member functions are named _M_xxx or _S_xxx, since those are non-public internals. Aside: I don't like the use of "NULL" in those diagnostics. That is a macro with the value 0 (or maybe 0L or 0LL or similar), not a pointer. You can't dereference NULL because it's not a pointer. It's just a macro that expands to a constant which *can be used to initialize a pointer_, but it's not a pointer itself. The bug here is a dereference of "a null pointer", not of the macro NULL. Or alternatively "null dereference", which is shorter and probably just as clear. But "dereference of NULL" is a category error.
