On Wed, 22 Apr 2026 at 12:51, Tomasz Kamiński <[email protected]> wrote:
>
> This implements LWG4290. Missing Mandates clauses on is_sufficiently_aligned.
>
> libstdc++-v3/ChangeLog:
>
> * include/bits/align.h (is_sufficiently_aligned): Mandate
> that _Align is power of two.
> * testsuite/20_util/is_sufficiently_aligned/2_neg.cc: New test.
> ---
> v2 replaces a test file used for chrono::format compilation time
> testing, with actual test for is_sufficiently_aligned.
>
> The test was included in previous run. OK for trunk?
OK
>
> libstdc++-v3/include/bits/align.h | 5 ++++-
> .../20_util/is_sufficiently_aligned/2_neg.cc | 12 ++++++++++++
> 2 files changed, 16 insertions(+), 1 deletion(-)
> create mode 100644
> libstdc++-v3/testsuite/20_util/is_sufficiently_aligned/2_neg.cc
>
> diff --git a/libstdc++-v3/include/bits/align.h
> b/libstdc++-v3/include/bits/align.h
> index 1a14e282216..3c8355d0e07 100644
> --- a/libstdc++-v3/include/bits/align.h
> +++ b/libstdc++-v3/include/bits/align.h
> @@ -116,7 +116,10 @@ align(size_t __align, size_t __size, void*& __ptr,
> size_t& __space) noexcept
> [[nodiscard,__gnu__::__always_inline__]]
> inline bool
> is_sufficiently_aligned(_Tp* __ptr)
> - { return reinterpret_cast<__UINTPTR_TYPE__>(__ptr) % _Align == 0; }
> + {
> + static_assert(std::has_single_bit(_Align));
> + return reinterpret_cast<__UINTPTR_TYPE__>(__ptr) % _Align == 0;
> + }
> #endif // __glibcxx_is_sufficiently_aligned
>
> _GLIBCXX_END_NAMESPACE_VERSION
> diff --git a/libstdc++-v3/testsuite/20_util/is_sufficiently_aligned/2_neg.cc
> b/libstdc++-v3/testsuite/20_util/is_sufficiently_aligned/2_neg.cc
> new file mode 100644
> index 00000000000..9db69b67ef6
> --- /dev/null
> +++ b/libstdc++-v3/testsuite/20_util/is_sufficiently_aligned/2_neg.cc
> @@ -0,0 +1,12 @@
> +// { dg-do compile { target c++26 } }
> +
> +#include <memory>
> +
> +void
> +test01(int* ptr)
> +{
> + (void)std::is_sufficiently_aligned<5>(ptr); // { dg-error "here" }
> + (void)std::is_sufficiently_aligned<7>(ptr); // { dg-error "here" }
> +}
> +
> +// { dg-error "static assertion failed" "" { target *-*-* } 0 }
> --
> 2.53.0
>