https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122172
--- Comment #21 from Hans-Peter Nilsson <hp at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #20) > (In reply to Hans-Peter Nilsson from comment #16) > > So, is this too ugly? (Please ignore the whitespace change.) > > > > diff --git a/libstdc++-v3/include/bits/shared_ptr_base.h > > b/libstdc++-v3/include/bits/shared_ptr_base.h > > index 0c6df64b921f..cd8be8b091fe 100644 > > --- a/libstdc++-v3/include/bits/shared_ptr_base.h > > +++ b/libstdc++-v3/include/bits/shared_ptr_base.h > > @@ -267,7 +267,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > // which would cause use_count() to return bogus values. > > constexpr _Atomic_word __max > > = sizeof(long) > sizeof(_Atomic_word) > > - ? -1 : __gnu_cxx::__int_traits<_Atomic_word>::__max; > > + ? -1 : (_Atomic_word_unsigned) -1 / 2; > > > > if (__count == __max) [[__unlikely__]] > > __builtin_trap(); > > I was testing the same thing locally :-) w00t! Time to post it? Or should I? But, if you instead are going with... (In reply to Jonathan Wakely from comment #4) > We could also just disable the warnings everywhere we use > make_unsigned<_Atomic_word>. They're harmless. ...this, because of... > We aren't doing atomic operations on the unsigned type, it only exists on > the stack as a local variable, and so it's fine if it's not 4-byte aligned. ...this, a word of caution: Please add sufficient documentation and commentary that the unsigned variant *must not* be used for atomic operations, or else that *will* "silently" happen in a future change (only because nothing says why that'd be wrong, and this type is conveniently available).
