blob: 7bca06bf074e566f2310b32acc86ee511504539c [file] [log] [blame]
Richard Smith762bb9d2011-10-13 22:29:44 +00001// RUN: %clang_cc1 -ffreestanding -fsyntax-only -verify -std=c++11 %s
Sean Huntc9858bc2011-05-19 20:36:08 +00002
3#include "limits.h"
4
5template<typename T, typename U>
6struct is_same_type {
7 static const bool value = false;
8};
9template <typename T>
10struct is_same_type<T, T> {
11 static const bool value = true;
12};
13
14__underlying_type(int) a; // expected-error {{only enumeration types}}
15__underlying_type(struct b) c; // expected-error {{only enumeration types}}
16
17enum class f : char;
18static_assert(is_same_type<char, __underlying_type(f)>::value,
19 "f has the wrong underlying type");
20
21enum g {d = INT_MIN };
22static_assert(is_same_type<int, __underlying_type(g)>::value,
23 "g has the wrong underlying type");
24
25__underlying_type(f) h;
26static_assert(is_same_type<char, decltype(h)>::value,
27 "h has the wrong type");
Sean Huntca63c202011-05-24 22:41:36 +000028
29template <typename T>
30struct underlying_type {
31 typedef __underlying_type(T) type; // expected-error {{only enumeration types}}
32};
33
34static_assert(is_same_type<underlying_type<f>::type, char>::value,
35 "f has the wrong underlying type in the template");
36
37underlying_type<int>::type e; // expected-note {{requested here}}
Peter Collingbourne12fc4b02012-03-05 16:02:06 +000038
39using uint = unsigned;
40enum class foo : uint { bar };
41
42static_assert(is_same_type<underlying_type<foo>::type, unsigned>::value,
43 "foo has the wrong underlying type");