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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 // type_traits
10 
11 // MSVC mode seems to use different rules regarding enum sizes, so E1
12 // doesn't cause an error.
13 // UNSUPPORTED: msvc
14 
15 // underlying_type
16 // Mandates: enum must not be an incomplete enumeration type.
17 
18 #include <type_traits>
19 #include <climits>
20 
21 #include "test_macros.h"
22 
23 enum E1 { E1Zero, E1One, E1Two = sizeof(std::underlying_type<E1>::type) }; // expected-error@type_traits:* {{cannot determine underlying type of incomplete enumeration type 'E1'}}
24 
25 //  None of these are incomplete.
26 //  Scoped enums have an underlying type of 'int' unless otherwise specified
27 //  Unscoped enums with a specified underlying type become complete as soon as that type is specified.
28 // enum E2 : char            { E2Zero, E2One, E2Two = sizeof(std::underlying_type<E2>::type) };
29 // enum class E3             { E3Zero, E3One, E3Two = sizeof(std::underlying_type<E3>::type) };
30 // enum struct E4 : unsigned { E4Zero, E4One, E4Two = sizeof(std::underlying_type<E4>::type) };
31 // enum struct E5            { E5Zero, E5One, E5Two = sizeof(std::underlying_type<E5>::type) };
32 // enum class E6 : unsigned  { E6Zero, E6One, E6Two = sizeof(std::underlying_type<E6>::type) };
33 
34 // These error messages will have to change if clang ever gets fixed. But at least they're being rejected.
35 enum E7        : std::underlying_type_t<E7> {}; // expected-error {{use of undeclared identifier 'E7'}}
36 enum class E8  : std::underlying_type_t<E8> {}; // expected-error {{use of undeclared identifier 'E8'}}
37 enum struct E9 : std::underlying_type_t<E9> {}; // expected-error {{use of undeclared identifier 'E9'}}
38 
main(int,char **)39 int main(int, char**)
40 {
41   return 0;
42 }
43