Files
gcc/libstdc++-v3/include/ext
Jonathan Wakely 385984f555 libstdc++: Fix warnings from std::make_unsigned<_Atomic_word> [PR122172]
GCC gives a -Wignored-attributes warning when a class template is
instantiated with a type that has an aligned(n) attribute. Specifically,
cris-elf uses 'typedef int __attribute_((__aligned(4))) _Atomic_word;'
and so compiling libstdc++ headers gives:
warning: ignoring attributes on template argument ‘int’ [-Wignored-attributes]

This commit reduces four occurrences of make_unsigned<_Atomic_word> into
two, one in bits/shared_ptr_base.h and one in ext/atomicity.h, and uses
diagnostic pragmas around the two remaining uses to avoid the warnings.
Because the unsigned type might have lost the alignment of _Atomic_word
that is needed for atomic ops (at least on cris-elf), the unsigned type
should only be used for plain non-atomic arithmetic. To prevent misuse,
it's defined as a private type in _Sp_counted_base, and is defined and
then undefined as a macro in ext/atomicity.h, so that it's not usable
after __exchange_and_add_single and __atomic_add_single have been
defined.

We also get a warning from instantiating __int_traits<_Atomic_word> in
shared_ptr_base.h which can be avoided by calculating the maximum signed
value from the maximum unsigned value.

libstdc++-v3/ChangeLog:

	PR libstdc++/122172
	* include/bits/shared_ptr_base.h (_Sp_counted_base): Define
	_Unsigned_count_type for make_unsigned<_Atomic_word>.
	Replace __int_traits<_Atomic_word> with equivalent expression.
	* include/ext/atomicity.h (_GLIBCXX_UNSIGNED_ATOMIC_WORD):
	Define macro for unsigned type to use for arithmetic.
	(__exchange_and_add_single, __atomic_add_single): Use it.

Reviewed-by: Hans-Peter Nilsson <hp@axis.com>
2025-10-11 00:09:19 +01:00
..