[Bug tree-optimization/108374] [12/13 Regression] unexpected -Wstringop-overflow when using std::atomic and std::shared_ptr
redi at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Thu Jan 12 09:57:34 GMT 2023
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108374
--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(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.
More information about the Gcc-bugs
mailing list