1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // UNSUPPORTED: c++98, c++03, c++11 11 // type_traits 12 13 // is_final 14 15 #include <type_traits> 16 #include "test_macros.h" 17 18 struct P final { }; 19 union U1 { }; 20 union U2 final { }; 21 22 template <class T> 23 void test_is_final() 24 { 25 static_assert( std::is_final<T>::value, ""); 26 static_assert( std::is_final<const T>::value, ""); 27 static_assert( std::is_final<volatile T>::value, ""); 28 static_assert( std::is_final<const volatile T>::value, ""); 29 #if TEST_STD_VER > 14 30 static_assert( std::is_final_v<T>, ""); 31 static_assert( std::is_final_v<const T>, ""); 32 static_assert( std::is_final_v<volatile T>, ""); 33 static_assert( std::is_final_v<const volatile T>, ""); 34 #endif 35 } 36 37 template <class T> 38 void test_is_not_final() 39 { 40 static_assert(!std::is_final<T>::value, ""); 41 static_assert(!std::is_final<const T>::value, ""); 42 static_assert(!std::is_final<volatile T>::value, ""); 43 static_assert(!std::is_final<const volatile T>::value, ""); 44 #if TEST_STD_VER > 14 45 static_assert(!std::is_final_v<T>, ""); 46 static_assert(!std::is_final_v<const T>, ""); 47 static_assert(!std::is_final_v<volatile T>, ""); 48 static_assert(!std::is_final_v<const volatile T>, ""); 49 #endif 50 } 51 52 int main () 53 { 54 test_is_not_final<int>(); 55 test_is_not_final<int*>(); 56 test_is_final <P>(); 57 test_is_not_final<P*>(); 58 test_is_not_final<U1>(); 59 test_is_not_final<U1*>(); 60 test_is_final <U2>(); 61 test_is_not_final<U2*>(); 62 } 63