| 1 |
// RUN: %clang_cc1 -triple %itanium_abi_triple -ffreestanding -fsyntax-only -verify -std=c++11 %s |
| 2 |
|
| 3 |
#include "limits.h" |
| 4 |
|
| 5 |
template<typename T, typename U> |
| 6 |
struct is_same_type { |
| 7 |
static const bool value = false; |
| 8 |
}; |
| 9 |
template <typename T> |
| 10 |
struct 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 |
|
| 17 |
enum class f : char; |
| 18 |
static_assert(is_same_type<char, __underlying_type(f)>::value, |
| 19 |
"f has the wrong underlying type"); |
| 20 |
|
| 21 |
enum g {d = INT_MIN }; |
| 22 |
static_assert(is_same_type<int, __underlying_type(g)>::value, |
| 23 |
"g has the wrong underlying type"); |
| 24 |
|
| 25 |
__underlying_type(f) h; |
| 26 |
static_assert(is_same_type<char, decltype(h)>::value, |
| 27 |
"h has the wrong type"); |
| 28 |
|
| 29 |
template <typename T> |
| 30 |
struct underlying_type { |
| 31 |
typedef __underlying_type(T) type; // expected-error {{only enumeration types}} |
| 32 |
}; |
| 33 |
|
| 34 |
static_assert(is_same_type<underlying_type<f>::type, char>::value, |
| 35 |
"f has the wrong underlying type in the template"); |
| 36 |
|
| 37 |
underlying_type<int>::type e; // expected-note {{requested here}} |
| 38 |
|
| 39 |
using uint = unsigned; |
| 40 |
enum class foo : uint { bar }; |
| 41 |
|
| 42 |
static_assert(is_same_type<underlying_type<foo>::type, unsigned>::value, |
| 43 |
"foo has the wrong underlying type"); |
| 44 |
|
| 45 |
namespace PR19966 { |
| 46 |
void PR19966(enum Invalid) { // expected-note 2{{forward declaration of}} |
| 47 |
// expected-error@-1 {{ISO C++ forbids forward references to 'enum'}} |
| 48 |
// expected-error@-2 {{variable has incomplete type}} |
| 49 |
__underlying_type(Invalid) dont_crash; |
| 50 |
// expected-error@-1 {{cannot determine underlying type of incomplete enumeration type 'Invalid'}} |
| 51 |
} |
| 52 |
enum E { // expected-note {{forward declaration of 'E'}} |
| 53 |
a = (__underlying_type(E)){} |
| 54 |
// expected-error@-1 {{cannot determine underlying type of incomplete enumeration type 'E'}} |
| 55 |
// expected-error@-2 {{constant expression}} |
| 56 |
}; |
| 57 |
} |
| 58 |
|
| 59 |
template<typename T> void f(__underlying_type(T)); |
| 60 |
template<typename T> void f(__underlying_type(T)); |
| 61 |
enum E {}; |
| 62 |
void PR26014() { f<E>(0); } // should not yield an ambiguity error. |
| 63 |
|
| 64 |
template<typename ...T> void f(__underlying_type(T) v); // expected-error {{declaration type contains unexpanded parameter pack 'T'}} |
| 65 |
|
| 66 |
namespace PR23421 { |
| 67 |
template <class T> |
| 68 |
using underlying_type_t = __underlying_type(T); |
| 69 |
// Should not crash. |
| 70 |
template <class T> |
| 71 |
struct make_unsigned_impl { using type = underlying_type_t<T>; }; |
| 72 |
using AnotherType = make_unsigned_impl<E>::type; |
| 73 |
|
| 74 |
// also should not crash. |
| 75 |
template <typename T> |
| 76 |
__underlying_type(T) ft(); |
| 77 |
auto x = &ft<E>; |
| 78 |
} |