1 //===----------------------------------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
13 // template<size_t N, class T>
14 // [[nodiscard]] constexpr T* assume_aligned(T* ptr);
20 #include "test_macros.h"
23 constexpr void check(T
* p
) {
24 ASSERT_SAME_TYPE(T
*, decltype(std::assume_aligned
<1>(p
)));
25 constexpr std::size_t alignment
= alignof(T
);
27 if constexpr (alignment
>= 1)
28 assert(p
== std::assume_aligned
<1>(p
));
29 if constexpr (alignment
>= 2)
30 assert(p
== std::assume_aligned
<2>(p
));
31 if constexpr (alignment
>= 4)
32 assert(p
== std::assume_aligned
<4>(p
));
33 if constexpr (alignment
>= 8)
34 assert(p
== std::assume_aligned
<8>(p
));
35 if constexpr (alignment
>= 16)
36 assert(p
== std::assume_aligned
<16>(p
));
37 if constexpr (alignment
>= 32)
38 assert(p
== std::assume_aligned
<32>(p
));
39 if constexpr (alignment
>= 64)
40 assert(p
== std::assume_aligned
<64>(p
));
41 if constexpr (alignment
>= 128)
42 assert(p
== std::assume_aligned
<128>(p
));
46 struct alignas( 4) S4
{ };
47 struct alignas( 8) S8
{ };
48 struct alignas( 16) S16
{ };
49 struct alignas( 32) S32
{ };
50 struct alignas( 64) S64
{ };
51 struct alignas(128) S128
{ };
53 constexpr bool tests() {
83 int main(int, char**) {
85 static_assert(tests());