blob: 8cb46cf98f843bb5986d7183b2837d72104f1a3e [file] [log] [blame]
Douglas Gregorc8ab2562009-05-31 09:31:02 +00001// RUN: clang-cc -fsyntax-only -verify %s
2template<typename T>
3struct is_pointer {
4 static const bool value = false;
5};
6
7template<typename T>
8struct is_pointer<T*> {
9 static const bool value = true;
10};
11
12template<typename T>
13struct is_pointer<const T*> {
14 static const bool value = true;
15};
16
17int array0[is_pointer<int>::value? -1 : 1];
18int array1[is_pointer<int*>::value? 1 : -1];
19int array2[is_pointer<const int*>::value? 1 : -1]; // expected-error{{partial ordering}} \
20// expected-error{{negative}}
Douglas Gregor0b9247f2009-06-04 00:03:07 +000021
Douglas Gregord560d502009-06-04 00:21:18 +000022template<typename T>
23struct is_lvalue_reference {
24 static const bool value = false;
25};
26
27template<typename T>
28struct is_lvalue_reference<T&> {
29 static const bool value = true;
30};
31
32int lvalue_ref0[is_lvalue_reference<int>::value? -1 : 1];
33int lvalue_ref1[is_lvalue_reference<const int&>::value? 1 : -1];
34
Douglas Gregor0b9247f2009-06-04 00:03:07 +000035template<typename T, typename U>
36struct is_same {
37 static const bool value = false;
38};
39
40template<typename T>
41struct is_same<T, T> {
42 static const bool value = true;
43};
44
45typedef int INT;
46typedef INT* int_ptr;
47
48int is_same0[is_same<int, int>::value? 1 : -1];
49int is_same1[is_same<int, INT>::value? 1 : -1];
50int is_same2[is_same<const int, int>::value? -1 : 1];
51int is_same3[is_same<int_ptr, int>::value? -1 : 1];
Anders Carlsson4d6fb502009-06-04 04:11:30 +000052
53template<typename T>
Douglas Gregor199d9912009-06-05 00:53:49 +000054struct remove_reference {
55 typedef T type;
56};
57
58template<typename T>
59struct remove_reference<T&> {
60 typedef T type;
61};
62
63int remove_ref0[is_same<remove_reference<int>::type, int>::value? 1 : -1];
64int remove_ref1[is_same<remove_reference<int&>::type, int>::value? 1 : -1];
65
66template<typename T>
Anders Carlsson4d6fb502009-06-04 04:11:30 +000067struct is_incomplete_array {
68 static const bool value = false;
69};
70
71template<typename T>
72struct is_incomplete_array<T[]> {
73 static const bool value = true;
74};
75
76int incomplete_array0[is_incomplete_array<int>::value ? -1 : 1];
77int incomplete_array1[is_incomplete_array<int[1]>::value ? -1 : 1];
78int incomplete_array2[is_incomplete_array<bool[]>::value ? 1 : -1];
79int incomplete_array3[is_incomplete_array<int[]>::value ? 1 : -1];
80
81template<typename T>
82struct is_array_with_4_elements {
83 static const bool value = false;
84};
85
86template<typename T>
87struct is_array_with_4_elements<T[4]> {
88 static const bool value = true;
89};
90
91int array_with_4_elements0[is_array_with_4_elements<int[]>::value ? -1 : 1];
92int array_with_4_elements1[is_array_with_4_elements<int[1]>::value ? -1 : 1];
93int array_with_4_elements2[is_array_with_4_elements<int[4]>::value ? 1 : -1];
94int array_with_4_elements3[is_array_with_4_elements<int[4][2]>::value ? 1 : -1];
Douglas Gregor199d9912009-06-05 00:53:49 +000095
96template<typename T>
97struct get_array_size;
98
99template<typename T, unsigned N>
100struct get_array_size<T[N]> {
101 static const unsigned value = N;
102};
103
104int array_size0[get_array_size<int[12]>::value == 12? 1 : -1];