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
17struct P final { };
18union U1 { };
19union U2 final { };
20
21template <class T>
22void 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
36template <class T>
37void 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
51int 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

source code of libcxx/test/std/utilities/meta/meta.unary/meta.unary.prop/is_final.pass.cpp