| 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // UNSUPPORTED: c++03, c++11 |
| 10 | // type_traits |
| 11 | |
| 12 | // is_final |
| 13 | |
| 14 | #include <type_traits> |
| 15 | #include "test_macros.h" |
| 16 | |
| 17 | struct P final { }; |
| 18 | union U1 { }; |
| 19 | union U2 final { }; |
| 20 | |
| 21 | template <class T> |
| 22 | void test_is_final() |
| 23 | { |
| 24 | static_assert( std::is_final<T>::value, "" ); |
| 25 | static_assert( std::is_final<const T>::value, "" ); |
| 26 | static_assert( std::is_final<volatile T>::value, "" ); |
| 27 | static_assert( std::is_final<const volatile T>::value, "" ); |
| 28 | #if TEST_STD_VER > 14 |
| 29 | static_assert( std::is_final_v<T>, "" ); |
| 30 | static_assert( std::is_final_v<const T>, "" ); |
| 31 | static_assert( std::is_final_v<volatile T>, "" ); |
| 32 | static_assert( std::is_final_v<const volatile T>, "" ); |
| 33 | #endif |
| 34 | } |
| 35 | |
| 36 | template <class T> |
| 37 | void test_is_not_final() |
| 38 | { |
| 39 | static_assert(!std::is_final<T>::value, "" ); |
| 40 | static_assert(!std::is_final<const T>::value, "" ); |
| 41 | static_assert(!std::is_final<volatile T>::value, "" ); |
| 42 | static_assert(!std::is_final<const volatile T>::value, "" ); |
| 43 | #if TEST_STD_VER > 14 |
| 44 | static_assert(!std::is_final_v<T>, "" ); |
| 45 | static_assert(!std::is_final_v<const T>, "" ); |
| 46 | static_assert(!std::is_final_v<volatile T>, "" ); |
| 47 | static_assert(!std::is_final_v<const volatile T>, "" ); |
| 48 | #endif |
| 49 | } |
| 50 | |
| 51 | int main(int, char**) |
| 52 | { |
| 53 | test_is_not_final<int>(); |
| 54 | test_is_not_final<int*>(); |
| 55 | test_is_final <P>(); |
| 56 | test_is_not_final<P*>(); |
| 57 | test_is_not_final<U1>(); |
| 58 | test_is_not_final<U1*>(); |
| 59 | test_is_final <U2>(); |
| 60 | test_is_not_final<U2*>(); |
| 61 | |
| 62 | return 0; |
| 63 | } |
| 64 | |