1 // Copyright (C) 2019 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library.  This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 // GNU General Public License for more details.
13 
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3.  If not see
16 // <http://www.gnu.org/licenses/>.
17 
18 // { dg-do compile { target c++11 } }
19 
20 #include <type_traits>
21 
22 // Test for SFINAE-friendly underlying_type
23 
24 template<typename T, typename = typename std::underlying_type<T>::type>
is_enum(int)25   constexpr bool is_enum(int) { return true; }
26 
27 template<typename T>
is_enum(...)28   constexpr bool is_enum(...) { return false; }
29 
30 void
test01()31 test01()
32 {
33   enum E { };
34   static_assert( is_enum<E>(0), "");
35 
36   static_assert( !is_enum<void>(0), "");
37   static_assert( !is_enum<int>(0), "");
38   static_assert( !is_enum<long>(0), "");
39   static_assert( !is_enum<int*>(0), "");
40   static_assert( !is_enum<int[]>(0), "");
41   static_assert( !is_enum<const int*>(0), "");
42   static_assert( !is_enum<const int&>(0), "");
43   static_assert( !is_enum<int()>(0), "");
44   static_assert( !is_enum<int(&)()>(0), "");
45   static_assert( !is_enum<int(*)()>(0), "");
46   struct S { };
47   static_assert( !is_enum<S>(0), "");
48   static_assert( !is_enum<S&>(0), "");
49   static_assert( !is_enum<S*>(0), "");
50   static_assert( !is_enum<int S::*>(0), "");
51   static_assert( !is_enum<int (S::*)()>(0), "");
52 }
53