1 // Copyright 2005 Alexander Nasonov.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 
6 #include <climits>
7 
8 #if !defined(BOOST_NO_CWCHAR)
9 #include <cwchar>
10 #endif
11 
12 #include "promote_util.hpp"
13 
14 struct Struct {};
15 
main()16 int main()
17 {
18     // char types
19 
20 #if CHAR_MAX <= INT_MAX
21     test_cv< char, int >();
22 #else
23     // TODO: dead branch?
24     test_cv< char, unsigned int >();
25 #endif
26 
27     test_cv< signed char, int >();
28 
29 #if UCHAR_MAX <= INT_MAX
30     test_cv< unsigned char, int >();
31 #else
32     test_cv< unsigned char, unsigned int >();
33 #endif
34 
35 
36     // short types
37 
38     test_cv< short int, int >();
39 
40 #if USHRT_MAX <= INT_MAX
41     test_cv< unsigned short, int >();
42 #else
43     test_cv< unsigned short, unsigned int >();
44 #endif
45 
46 
47     // int and long
48 
49     test_cv< int,           int           >();
50     test_cv< unsigned int,  unsigned int  >();
51     test_cv< long,          long          >();
52     test_cv< unsigned long, unsigned long >();
53 
54     // wchar_t
55 
56 #if !defined(BOOST_NO_CWCHAR) && defined(WCHAR_MAX) && defined(WCHAR_MIN)
57 
58 // Version prior to VC8 didn't allow WCHAR_MAX in #if expressions
59 #if defined(BOOST_MSVC) && BOOST_MSVC < 1400
60 #  define BOOST_TT_AUX_WCHAR_MAX USHORT_MAX // force test_cv< wchar_t, int >
61 #elif defined(WCHAR_MAX) && !defined(__APPLE__)
62 #  define BOOST_TT_AUX_WCHAR_MAX WCHAR_MAX
63 #elif defined(__BORLANDC__) || defined(__CYGWIN__) || defined(__MINGW32__) || (defined(__BEOS__) && defined(__GNUC__))
64     // No WCHAR_MIN and WCHAR_MAX, whar_t is short and unsigned:
65 #  define BOOST_TT_AUX_WCHAR_MAX USHORT_MAX // force test_cv< wchar_t, int >
66 #elif (defined(__sgi) && (!defined(__SGI_STL_PORT) || __SGI_STL_PORT < 0x400))\
67     || (defined __APPLE__)\
68     || (defined(__OpenBSD__) && defined(__GNUC__))\
69     || (defined(__NetBSD__) && defined(__GNUC__))\
70     || (defined(__FreeBSD__) && defined(__GNUC__))\
71     || (defined(__DragonFly__) && defined(__GNUC__))\
72     || (defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 3) && !defined(__SGI_STL_PORT))
73     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as int.
74     //  - SGI MIPSpro with native library
75     //  - gcc 3.x on HP-UX
76     //  - Mac OS X with native library
77     //  - gcc on FreeBSD, OpenBSD and NetBSD
78 #  define BOOST_TT_AUX_WCHAR_MAX INT_MAX // force test_cv< wchar_t, int >
79 #elif defined(__hpux) && defined(__GNUC__) && (__GNUC__ == 2) && !defined(__SGI_STL_PORT)
80     // No WCHAR_MIN and WCHAR_MAX, wchar_t has the same range as unsigned int.
81     //  - gcc 2.95.x on HP-UX
82     // (also, std::numeric_limits<wchar_t> appears to return the wrong values).
83 #  define BOOST_TT_AUX_WCHAR_MAX UINT_MAX // force test_cv< wchar_t, int >
84 #endif
85 
86 // For this PP-logic to work we need a valid WCHAR_MAX etc:
87 #if defined(BOOST_TT_AUX_WCHAR_MAX) \
88    && !defined(__DECCXX) \
89    && !defined(__hpux) \
90    && !defined(_WIN32_WCE)
91 
92 #if BOOST_TT_AUX_WCHAR_MAX <= INT_MAX
93     test_cv< wchar_t, int >();
94 #elif WCHAR_MIN == 0 && BOOST_TT_AUX_WCHAR_MAX <= UINT_MAX
95     test_cv< wchar_t, unsigned int >();
96 #elif BOOST_TT_AUX_WCHAR_MAX <= LONG_MAX
97     test_cv< wchar_t, long >();
98 #else
99     test_cv< wchar_t, unsigned long >();
100 #endif
101 
102 #endif
103 
104 #undef BOOST_TT_AUX_WCHAR_MAX
105 
106 #endif
107 
108 
109     // floating point promotion
110 
111     test_cv< float , double >();
112     test_cv< double, double >();
113 
114 
115     // Other types
116 
117     test_cv< Struct, Struct >();
118     test_cv< void  , void   >();
119     test_cv< void* , void*  >();
120 
121     // Array types
122 
123     typedef int arr[3];
124     typedef int (&arr_ref)[3];
125     typedef int (*arr_ptr)[3];
126 
127     test_cv< arr    , arr     >();
128     test_cv< arr_ptr, arr_ptr >();
129 
130     test_no_cv<arr_ref,arr_ref>();
131 
132 
133     // Function types
134 
135     typedef int (fun)();
136     typedef int (&fun_ref)();
137     typedef int (*fun_ptr)();
138 
139     test_no_cv< fun    , fun     >();
140     test_no_cv< fun_ref, fun_ref >();
141     test_no_cv< fun_ptr, fun_ptr >();
142 
143     // Member pointer types
144 
145     typedef int (Struct::*mem_fun_ptr)();
146     typedef int Struct::*mem_ptr;
147 
148     test_no_cv< mem_ptr,     mem_ptr     >();
149     test_no_cv< mem_fun_ptr, mem_fun_ptr >();
150 
151     return 0;
152 }
153 
154