https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121052
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #0) > Many of our uses of the nonnull attribute are probably bugs, e.g. > > polymorphic_allocator(memory_resource* __r) noexcept > __attribute__((__nonnull__)) > : _M_resource(__r) > { _GLIBCXX_DEBUG_ASSERT(__r); } > > This debug assertion never fails in optimized builds, because the nonnull > attribute tells the compiler that __r is not null, so the assertion is > optimized out as dead code. Maybe my thinking here was that builds using _GLIBCXX_DEBUG are more likely to be done with -O0 and in that case, the attribute would not remove the assertion. So it can still find bugs in user code sometimes.