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 // type_traits 11 12 // underlying_type 13 14 #include <type_traits> 15 #include <climits> 16 17 #include "test_macros.h" 18 19 enum E { V = INT_MIN }; 20 21 #if !defined(_WIN32) || defined(__MINGW32__) 22 #define TEST_UNSIGNED_UNDERLYING_TYPE 1 23 #else 24 #define TEST_UNSIGNED_UNDERLYING_TYPE 0 // MSVC's ABI doesn't follow the Standard 25 #endif 26 27 #if TEST_UNSIGNED_UNDERLYING_TYPE 28 enum F { W = UINT_MAX }; 29 #endif // TEST_UNSIGNED_UNDERLYING_TYPE 30 31 int main() 32 { 33 static_assert((std::is_same<std::underlying_type<E>::type, int>::value), 34 "E has the wrong underlying type"); 35 #if TEST_UNSIGNED_UNDERLYING_TYPE 36 static_assert((std::is_same<std::underlying_type<F>::type, unsigned>::value), 37 "F has the wrong underlying type"); 38 #endif // TEST_UNSIGNED_UNDERLYING_TYPE 39 40 #if TEST_STD_VER > 11 41 static_assert((std::is_same<std::underlying_type_t<E>, int>::value), ""); 42 #if TEST_UNSIGNED_UNDERLYING_TYPE 43 static_assert((std::is_same<std::underlying_type_t<F>, unsigned>::value), ""); 44 #endif // TEST_UNSIGNED_UNDERLYING_TYPE 45 #endif // TEST_STD_VER > 11 46 47 #if TEST_STD_VER >= 11 48 enum G : char { }; 49 50 static_assert((std::is_same<std::underlying_type<G>::type, char>::value), 51 "G has the wrong underlying type"); 52 #if TEST_STD_VER > 11 53 static_assert((std::is_same<std::underlying_type_t<G>, char>::value), ""); 54 #endif // TEST_STD_VER > 11 55 #endif // TEST_STD_VER >= 11 56 } 57