https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108374
--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #3) > (In reply to Romain Geissler from comment #0) > > std::weak_ptr<A> weakPointer(pointer); > > > > [[maybe_unused]] const unsigned int aAttr = weakPointer.lock()->_attr; > > If pointer == nullptr then weakPointer.lock() is also null, and so > dereferencing it to access the attr member is undefined, and does indeed > perform an atomic load at address 0. > > Instead of complaining about it, I would expect GCC to treat that undefined > condition as unreachable and optimize it away. Hmm, but then the program is bogus, no? And a diagnostic warranted. At least if it is well-defined to have a nullptr == pointer. So I'd be inclined to close as INVALID?