]> git.ipfire.org Git - thirdparty/gcc.git/commit
libstdc++: More user-friendly failed assertions from shared_ptr dereference
authorJonathan Wakely <jwakely@redhat.com>
Wed, 30 Oct 2024 11:41:47 +0000 (11:41 +0000)
committerJonathan Wakely <redi@gcc.gnu.org>
Wed, 6 Nov 2024 12:47:19 +0000 (12:47 +0000)
commit1b169ee7e25129fede3aadbeb72037017d1d5a47
tree93488036bc9ff490382b315e8dbe01a98415b243
parentf7979b8bfa6542e6861f44c78d18cc1cf8dae4d6
libstdc++: More user-friendly failed assertions from shared_ptr dereference

Currently dereferencing an empty shared_ptr prints a complicated
internal type in the assertion message:

include/bits/shared_ptr_base.h:1377: std::__shared_ptr_access<_Tp, _Lp, <anonymous>, <anonymous> >::element_type& std::__shared_ptr_access<_Tp, _Lp, <anonymous>, <anonymous> >::operator*() const [with _Tp = std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic; bool <anonymous> = false; bool <anonymous> = false; element_type = std::filesystem::__cxx11::recursive_directory_iterator::_Dir_stack]: Assertion '_M_get() != nullptr' failed.

Users don't care about any of the _Lp and <anonymous> template
parameters, so this is unnecessarily verbose.

We can simplify it to something that only mentions "shared_ptr_deref"
and the element type:

include/bits/shared_ptr_base.h:1371: _Tp* std::__shared_ptr_deref(_Tp*) [with _Tp = filesystem::__cxx11::recursive_directory_iterator::_Dir_stack]: Assertion '__p != nullptr' failed.

libstdc++-v3/ChangeLog:

* include/bits/shared_ptr_base.h (__shared_ptr_deref): New
function template.
(__shared_ptr_access, __shared_ptr_access<>): Use it.
libstdc++-v3/include/bits/shared_ptr_base.h