libstdc++: Add hint to compiler about vector invariants [PR106434]
authorJonathan Wakely <jwakely@redhat.com>
Mon, 5 Dec 2022 12:53:42 +0000 (12:53 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 6 Dec 2022 21:33:29 +0000 (21:33 +0000)
commit4ba94abf147fe7778a7541849ce27cafee74df9b
tree74224142ac680223ae72453aee46f1aaede82f85
parentaf177d7280668e5b21560165dc828754618e6621
libstdc++: Add hint to compiler about vector invariants [PR106434]

The PR shows a bogus warning where jump threading generates code for the
undefined case that the insertion point is a value-initialized iterator
but _M_finish and _M_end_of_storage are unequal (so at least one must be
non-null). Using __builtin_unreachable() removes the bogus warning. Also
add an assertion to diagnose undefined misuses of a null iterator here,
so we don't just silently optimize that undefined code to something
unsafe.

libstdc++-v3/ChangeLog:

PR c++/106434
* include/bits/vector.tcc (insert(const_iterator, const T&)):
Add assertion and optimization hint that the iterator for the
insertion point must be non-null.
libstdc++-v3/include/bits/vector.tcc