Author: sebor
Date: Mon Jan 30 15:30:07 2006
New Revision: 373631
URL: http://svn.apache.org/viewcvs?rev=373631&view=rev
Log:
2006-01-30 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-34
* cstdint: Simplified.
* 8.cstdint.cpp: New test exercising tr.c99.cstdint.
Added:
incubator/stdcxx/trunk/tests/tr1.c99/
incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp (with props)
Modified:
incubator/stdcxx/trunk/include/tr1/cstdint
Modified: incubator/stdcxx/trunk/include/tr1/cstdint
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/include/tr1/cstdint?rev=373631&r1=373630&r2=373631&view=diff
==============================================================================
--- incubator/stdcxx/trunk/include/tr1/cstdint (original)
+++ incubator/stdcxx/trunk/include/tr1/cstdint Mon Jan 30 15:30:07 2006
@@ -48,27 +48,19 @@
#ifdef _RWSTD_INT8_T
+// optional exact width types
typedef _RWSTD_INT8_T int8_t;
typedef _RWSTD_UINT8_T uint8_t;
-typedef _RWSTD_INT8_T int_least8_t;
-typedef _RWSTD_UINT8_T uint_least8_t;
-typedef _RWSTD_INT8_T int_fast8_t;
-typedef _RWSTD_UINT8_T uint_lfast8_t;
# define INT8_MAX 127
# define UINT8_MAX 255U
-# define INT_LEAST8_MAX 127
-# define UINT_LEAST8_MAX 255U
-# define INT_FAST8_MAX 127
-# define UINT_FAST8_MAX 255U
+# define INT_LEAST8_MAX INT8_MAX
+# define UINT_LEAST8_MAX UINT8_MAX
+# define INT_FAST8_MAX INT8_MAX
+# define UINT_FAST8_MAX UINT8_MAX
#elif defined (_RWSTD_INT16_T)
-typedef _RWSTD_INT16_T int_least8_t;
-typedef _RWSTD_UINT16_T uint_least8_t;
-typedef _RWSTD_INT16_T int_fast8_t;
-typedef _RWSTD_UINT16_T uint_fast8_t;
-
# define INT_LEAST8_MAX 32767
# define UINT_LEAST8_MAX 65535U
# define INT_FAST8_MAX 32767
@@ -76,23 +68,20 @@
#elif defined (_RWSTD_INT32_T)
-typedef _RWSTD_INT32_T int_least8_t;
-typedef _RWSTD_UINT32_T uint_least8_t
-typedef _RWSTD_INT32_T int_fast8_t;
-typedef _RWSTD_UINT32_T uint_fast8_t
-
-# define INT_LEAST8_MAX 2147483647
-# define UINT_LEAST8_MAX 4294967295U
-# define INT_FAST8_MAX 2147483647
-# define UINT_FAST8_MAX 4294967295U
+# if 4 == _RWSTD_INT_SIZE
+# define INT_LEAST8_MAX _RWSTD_INT_MAX
+# define UINT_LEAST8_MAX _RWSTD_UINT_MAX
+# define INT_FAST8_MAX _RWSTD_INT_MAX
+# define UINT_FAST8_MAX _RWSTD_UINT_MAX
+# elif 4 == _RWSTD_LONG_SIZE
+# define INT_LEAST8_MAX _RWSTD_LONG_MAX
+# define UINT_LEAST8_MAX _RWSTD_ULONG_MAX
+# define INT_FAST8_MAX _RWSTD_LONG_MAX
+# define UINT_FAST8_MAX _RWSTD_ULONG_MAX
+# endif
#elif defined (_RWSTD_INT64_T)
-typedef _RWSTD_INT64_T int_least8_t;
-typedef _RWSTD_UINT64_T uint_least8_t
-typedef _RWSTD_INT64_T int_fast8_t;
-typedef _RWSTD_UINT64_T uint_fast8_t
-
# if 8 == _RWSTD_LONG_SIZE
# define INT_LEAST8_MAX _RWSTD_LONG_MAX
# define UINT_LEAST8_MAX _RWSTD_ULONG_MAX
@@ -107,11 +96,6 @@
#else // fallback on int
-typedef int int_least8_t;
-typedef unsigned uint_least8_t
-typedef int int_fast8_t;
-typedef unsigned uint_fast8_t
-
# define INT_LEAST8_MAX _RWSTD_INT_MAX
# define UINT_LEAST8_MAX _RWSTD_UINT_MAX
# define INT_FAST8_MAX _RWSTD_INT_MAX
@@ -124,39 +108,34 @@
#ifdef _RWSTD_INT16_T
+// optional exact width types
typedef _RWSTD_INT16_T int16_t;
typedef _RWSTD_UINT16_T uint16_t;
-typedef _RWSTD_INT16_T int_least16_t;
-typedef _RWSTD_UINT16_T uint_least16_t;
-typedef _RWSTD_INT16_T int_fast16_t;
-typedef _RWSTD_UINT16_T uint_fast16_t;
# define INT16_MAX 32767
# define UINT16_MAX 65535U
-# define INT_LEAST16_MAX 32767
-# define UINT_LEAST16_MAX 65535U
-# define INT_FAST16_MAX 32767
-# define UINT_FAST16_MAX 65535U
+
+# define INT_LEAST16_MAX INT16_MAX
+# define UINT_LEAST16_MAX UINT16_MAX
+# define INT_FAST16_MAX INT16_MAX
+# define UINT_FAST16_MAX UINT16_MAX
#elif defined (_RWSTD_INT32_T)
-typedef _RWSTD_INT32_T int_least16_t;
-typedef _RWSTD_UINT32_T uint_least16_t
-typedef _RWSTD_INT32_T int_fast16_t;
-typedef _RWSTD_UINT32_T uint_fast16_t;
-
-# define INT_LEAST16_MAX 2147483647
-# define UINT_LEAST16_MAX 4294967295U
-# define INT_FAST16_MAX 2147483647
-# define UINT_FAST16_MAX 4294967295U
+# if 4 == _RWSTD_INT_SIZE
+# define INT_LEAST16_MAX _RWSTD_INT_MAX
+# define UINT_LEAST16_MAX _RWSTD_UINT_MAX
+# define INT_FAST16_MAX _RWSTD_INT_MAX
+# define UINT_FAST16_MAX _RWSTD_UINT_MAX
+# elif 4 == _RWSTD_LONG_SIZE
+# define INT_LEAST16_MAX _RWSTD_LONG_MAX
+# define UINT_LEAST16_MAX _RWSTD_ULONG_MAX
+# define INT_FAST16_MAX _RWSTD_LONG_MAX
+# define UINT_FAST16_MAX _RWSTD_ULONG_MAX
+# endif
#elif defined (_RWSTD_INT64_T)
-typedef _RWSTD_INT64_T int_least16_t;
-typedef _RWSTD_UINT64_T uint_least16_t
-typedef _RWSTD_INT64_T int_fast16_t;
-typedef _RWSTD_UINT64_T uint_fast16_t;
-
# if 8 == _RWSTD_LONG_SIZE
# define INT_LEAST16_MAX _RWSTD_LONG_MAX
# define UINT_LEAST16_MAX _RWSTD_ULONG_MAX
@@ -171,11 +150,6 @@
#else // fallback on int
-typedef int int_least16_t;
-typedef unsigned uint_least16_t
-typedef int int_fast16_t;
-typedef unsigned uint_fast16_t
-
# define INT_LEAST16_MAX _RWSTD_INT_MAX
# define UINT_LEAST16_MAX _RWSTD_UINT_MAX
# define INT_FAST16_MAX _RWSTD_INT_MAX
@@ -188,26 +162,24 @@
#ifdef _RWSTD_INT32_T
+// optional exact width types
typedef _RWSTD_INT32_T int32_t;
typedef _RWSTD_UINT32_T uint32_t;
-typedef _RWSTD_INT32_T int_least32_t;
-typedef _RWSTD_UINT32_T uint_least32_t;
-typedef _RWSTD_INT32_T int_faast32_t;
-typedef _RWSTD_UINT32_T uint_faast32_t;
-
-# define INT32_MAX 2147483647
-# define UINT32_MAX 4294967295U
-# define INT_LEAST32_MAX 2147483647
-# define UINT_LEAST32_MAX 4294967295U
-# define INT_FAST32_MAX 2147483647
-# define UINT_FAST32_MAX 4294967295U
-#elif defined (_RWSTD_INT64_T)
+# if 4 == _RWSTD_INT_SIZE
+# define INT32_MAX _RWSTD_INT_MAX
+# define UINT32_MAX _RWSTD_UINT_MAX
+# elif 4 == _RWSTD_LONG_SIZE
+# define INT32_MAX _RWSTD_LONG_MAX
+# define UINT32_MAX _RWSTD_LONG_MAX
+# endif
-typedef _RWSTD_INT64_T int_least32_t;
-typedef _RWSTD_UINT64_T uint_least32_t
-typedef _RWSTD_INT64_T int_fast32_t;
-typedef _RWSTD_UINT64_T uint_fast32_t
+# define INT_LEAST32_MAX INT32_MAX
+# define UINT_LEAST32_MAX UINT32_MAX
+# define INT_FAST32_MAX INT32_MAX
+# define UINT_FAST32_MAX UINT32_MAX
+
+#elif defined (_RWSTD_INT64_T)
# if 8 == _RWSTD_LONG_SIZE
# define INT_LEAST32_MAX _RWSTD_LONG_MAX
@@ -223,11 +195,6 @@
#else // fallback on int
-typedef int int_least32_t;
-typedef unsigned uint_least32_t
-typedef int int_faast32_t;
-typedef unsigned uint_faast32_t
-
# define INT32_MAX _RWSTD_INT_MAX
# define UINT32_MAX _RWSTD_UINT_MAX
# define INT_LEAST32_MAX _RWSTD_INT_MAX
@@ -242,12 +209,9 @@
#ifdef _RWSTD_INT64_T
+// optional exact width types
typedef _RWSTD_INT64_T int64_t;
typedef _RWSTD_UINT64_T uint64_t;
-typedef _RWSTD_INT64_T int_least64_t;
-typedef _RWSTD_UINT64_T uint_least64_t;
-typedef _RWSTD_INT64_T int_fast64_t;
-typedef _RWSTD_UINT64_T uint_fast64_t;
// 7.18.2.5 of C99 requires that intmax_t be at least 64-bits wide
typedef _RWSTD_INT64_T intmax_t;
@@ -256,25 +220,33 @@
# if 8 == _RWSTD_LONG_SIZE
# define INT64_MAX _RWSTD_LONG_MAX
# define UINT64_MAX _RWSTD_ULONG_MAX
-# define INT_LEAST64_MAX _RWSTD_LONG_MAX
-# define UINT_LEAST64_MAX _RWSTD_ULONG_MAX
-# define INT_FAST64_MAX _RWSTD_LONG_MAX
-# define UINT_FAST64_MAX _RWSTD_ULONG_MAX
# elif 8 == _RWSTD_LLONG_SIZE
# define INT64_MAX _RWSTD_LLONG_MAX
# define UINT64_MAX _RWSTD_ULLONG_MAX
-# define INT_LEAST64_MAX _RWSTD_LLONG_MAX
-# define UINT_LEAST64_MAX _RWSTD_ULLONG_MAX
-# define INT_FAST64_MAX _RWSTD_LLONG_MAX
-# define UINT_FAST64_MAX _RWSTD_ULLONG_MAX
# endif
+# define INT_LEAST64_MAX INT64_MAX
+# define UINT_LEAST64_MAX UINT64_MAX
+# define INT_FAST64_MAX INT64_MAX
+# define UINT_FAST64_MAX UINT64_MAX
+
+#elif defined (_RWSTD_LONG_LONG) // fallback on long long
+
+// this possibly violates 7.18.2.5 of C99 which requires that intmax_t
+// be at least 64-bits wide
+typedef _RWSTD_LONG_LONG intmax_t;
+typedef unsigned _RWSTD_LONG_LONG uintmax_t;
+
#else // fallback on long
-typedef long intmax_t;
-typedef unsigned long uintmax_t;
+
+// this likely violates 7.18.2.5 of C99 which requires that intmax_t
+// be at least 64-bits wide
+typedef long intmax_t;
+typedef unsigned long uintmax_t;
+
#endif // _RWSTD_INT{64,32,16}_T
-/*** intptr_t**************************************************************/
+/*** intptr_t *************************************************************/
#if 8 == _RWSTD_PTR_SIZE
@@ -284,8 +256,6 @@
# define INTPTR_MAX INT64_MAX
# define UINTPTR_MAX UINT64_MAX
-#define INTPTR_MIN _
-
#elif 4 == _RWSTD_PTR_SIZE
typedef _RWSTD_INT32_T intptr_t;
@@ -312,10 +282,45 @@
#endif // {8,16,32,64} == _RWSTD_PTR_SIZE
-/*** _MIN constants *******************************************************/
+/*** least and fast types *************************************************/
+
+typedef _RWSTD_INT_LEAST8_T int_least8_t;
+typedef _RWSTD_UINT_LEAST8_T uint_least8_t;
+typedef _RWSTD_INT_LEAST8_T int_fast8_t;
+typedef _RWSTD_UINT_LEAST8_T uint_fast8_t;
+
+typedef _RWSTD_INT_LEAST16_T int_least16_t;
+typedef _RWSTD_UINT_LEAST16_T uint_least16_t;
+typedef _RWSTD_INT_LEAST16_T int_fast16_t;
+typedef _RWSTD_UINT_LEAST16_T uint_fast16_t;
-#define PTRDIFF_MIN _RWSTD_PTRIDFF_MIN
-#define PTRDIFF_MAX _RWSTD_PTRIDFF_MAX
+typedef _RWSTD_INT_LEAST32_T int_least32_t;
+typedef _RWSTD_UINT_LEAST32_T uint_least32_t;
+typedef _RWSTD_INT_LEAST32_T int_fast32_t;
+typedef _RWSTD_UINT_LEAST32_T uint_fast32_t;
+
+#ifdef _RWSTD_INT_LEAST64_T
+
+typedef _RWSTD_INT_LEAST64_T int_least64_t;
+typedef _RWSTD_UINT_LEAST64_T uint_least64_t;
+typedef _RWSTD_INT_LEAST64_T int_fast64_t;
+typedef _RWSTD_UINT_LEAST64_T uint_fast64_t;
+
+#endif // _RWSTD_INT_LEAST64_T
+
+#ifdef _RWSTD_INT_LEAST128_T
+
+typedef _RWSTD_INT_LEAST128_T int_least128_t;
+typedef _RWSTD_UINT_LEAST128_T uint_least128_t;
+typedef _RWSTD_INT_LEAST128_T int_fast128_t;
+typedef _RWSTD_UINT_LEAST128_T uint_fast128_t;
+
+#endif // _RWSTD_INT_LEAST128_T
+
+/*** other constants ******************************************************/
+
+#define PTRDIFF_MIN _RWSTD_PTRDIFF_MIN
+#define PTRDIFF_MAX _RWSTD_PTRDIFF_MAX
#define SIZE_MAX _RWSTD_SIZE_MAX
@@ -327,6 +332,8 @@
#define SIG_ATOMIC_MIN _RWSTD_SIG_ATOMIC_MIN
#define SIG_ATOMIC_MAX _RWSTD_SIG_ATOMIC_MAX
+
+/*** computed _MIN constants **********************************************/
#define INT8_MIN _RWSTD_T_MIN (INT8_MAX)
#define INT16_MIN _RWSTD_T_MIN (INT16_MAX)
Added: incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp
URL:
http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp?rev=373631&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp (added)
+++ incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp Mon Jan 30 15:30:07 2006
@@ -0,0 +1,769 @@
+// -*- C++ -*-
+/***************************************************************************
+ *
+ * 8.cstdint.cpp - test exercising tr.c99.cstdint
+ *
+ * $Id$
+ *
+ ***************************************************************************
+ *
+ * Copyright 2006 The Apache Software Foundation or its licensors,
+ * as applicable.
+ *
+ * Copyright 2006 Rogue Wave Software.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ **************************************************************************/
+
+enum {
+ // these are expected to be hidden by macros #defined in <cstdint>
+ // #included below; references to macros that are not #defined in
+ // the header will silently use these enumerators and prevent
+ // compilation errors that would result otherwise
+ PTRDIFF_MIN, PTRDIFF_MAX,
+ SIZE_MAX,
+ WCHAR_MIN, WCHAR_MAX,
+ WINT_MIN, WINT_MAX,
+ SIG_ATOMIC_MIN, SIG_ATOMIC_MAX,
+ INT8_MIN, INT8_MAX,
+ INT16_MIN, INT16_MAX,
+ INT32_MIN, INT32_MAX,
+ INT64_MIN, INT64_MAX,
+ INT_LEAST8_MIN, INT_LEAST8_MAX,
+ INT_LEAST16_MIN, INT_LEAST16_MAX,
+ INT_LEAST32_MIN, INT_LEAST32_MAX,
+ INT_LEAST64_MIN, INT_LEAST64_MAX,
+ INT_FAST8_MIN, INT_FAST8_MAX,
+ INT_FAST16_MIN, INT_FAST16_MAX,
+ INT_FAST32_MIN, INT_FAST32_MAX,
+ INT_FAST64_MIN, INT_FAST64_MAX,
+ INTPTR_MAX,
+
+ UINT8_MIN, UINT8_MAX,
+ UINT16_MIN, UINT16_MAX,
+ UINT32_MIN, UINT32_MAX,
+ UINT64_MIN, UINT64_MAX,
+ UINT_LEAST8_MIN, UINT_LEAST8_MAX,
+ UINT_LEAST16_MIN, UINT_LEAST16_MAX,
+ UINT_LEAST32_MIN, UINT_LEAST32_MAX,
+ UINT_LEAST64_MIN, UINT_LEAST64_MAX,
+ UINT_FAST8_MIN, UINT_FAST8_MAX,
+ UINT_FAST16_MIN, UINT_FAST16_MAX,
+ UINT_FAST32_MIN, UINT_FAST32_MAX,
+ UINT_FAST64_MIN, UINT_FAST64_MAX,
+ UINTPTR_MAX
+};
+
+
+#include <tr1/cstdint>
+
+#include <driver.h>
+
+/**************************************************************************/
+
+static int rw_opt_no_macros; // for --no-macros
+static int rw_opt_no_types; // for --no-types
+static int rw_opt_no_64_bit; // for --no-64-bit
+
+/**************************************************************************/
+
+
+static const char* const
+missing_macros[] = {
+
+#ifndef INT_LEAST8_MIN
+ "INT_LEAST8_MIN",
+#else
+ "",
+#endif // INT_LEAST8_MIN
+
+#ifndef INT_FAST8_MIN
+ "INT_FAST8_MIN",
+#else
+ "",
+#endif // INT_FAST8_MIN
+
+#ifndef INT_LEAST16_MIN
+ "INT_LEAST16_MIN",
+#else
+ "",
+#endif // INT_LEAST16_MIN
+
+#ifndef INT_FAST16_MIN
+ "INT_FAST16_MIN",
+#else
+ "",
+#endif // INT_FAST16_MIN
+
+
+#ifndef INT_LEAST32_MIN
+ "INT_LEAST32_MIN",
+#else
+ "",
+#endif // INT_LEAST32_MIN
+
+#ifndef INT_FAST32_MIN
+ "INT_FAST32_MIN",
+#else
+ "",
+#endif // INT_FAST32_MIN
+
+
+#ifndef INT_LEAST8_MAX
+ "INT_LEAST8_MAX",
+#else
+ "",
+#endif // INT_LEAST8_MAX
+
+#ifndef UINT_LEAST8_MAX
+ "UINT_LEAST8_MAX",
+#else
+ "",
+#endif // UINT_LEAST8_MAX
+
+#ifndef INT_FAST8_MAX
+ "INT_FAST8_MAX",
+#else
+ "",
+#endif // INT_FAST8_MAX
+
+#ifndef UINT_FAST8_MAX
+ "UINT_FAST8_MAX",
+#else
+ "",
+#endif // UINT_FAST8_MAX
+
+
+#ifndef INT_LEAST16_MAX
+ "INT_LEAST16_MAX",
+#else
+ "",
+#endif // INT_LEAST16_MAX
+
+#ifndef UINT_LEAST16_MAX
+ "UINT_LEAST16_MAX",
+#else
+ "",
+#endif // UINT_LEAST16_MAX
+
+#ifndef INT_FAST16_MAX
+ "INT_FAST16_MAX",
+#else
+ "",
+#endif // INT_FAST16_MAX
+
+#ifndef UINT_FAST16_MAX
+ "UINT_FAST16_MAX",
+#else
+ "",
+#endif // UINT_FAST16_MAX
+
+
+#ifndef INT_LEAST32_MAX
+ "INT_LEAST32_MAX",
+#else
+ "",
+#endif // INT_LEAST32_MAX
+
+#ifndef UINT_LEAST32_MAX
+ "UINT_LEAST32_MAX",
+#else
+ "",
+#endif // UINT_LEAST32_MAX
+
+#ifndef INT_FAST32_MAX
+ "INT_FAST32_MAX",
+#else
+ "",
+#endif // INT_FAST32_MAX
+
+#ifndef UINT_FAST32_MAX
+ "UINT_FAST32_MAX",
+#else
+ "",
+#endif // UINT_FAST32_MAX
+
+#ifndef INTPTR_MAX
+ "INTPTR_MAX",
+#else
+ "",
+#endif // INTPTR_MAX
+
+#ifndef UINTPTR_MAX
+ "UINTPTR_MAX",
+#else
+ "",
+#endif // UINTPTR_MAX
+
+#ifndef PTRDIFF_MIN
+ "PTRDIFF_MIN",
+#else
+ "",
+#endif // PTRDIFF_MIN
+
+#ifndef PTRDIFF_MAX
+ "PTRDIFF_MAX",
+#else
+ "",
+#endif // PTRDIFF_MAX
+
+#ifndef SIZE_MAX
+ "SIZE_MAX",
+#else
+ "",
+#endif // SIZE_MAX
+
+#ifndef WCHAR_MIN
+ "WCHAR_MIN",
+#else
+ "",
+#endif // WCHAR_MIN
+
+#ifndef WCHAR_MAX
+ "WCHAR_MAX",
+#else
+ "",
+#endif // WCHAR_MAX
+
+#ifndef WINT_MIN
+ "WINT_MIN",
+#else
+ "",
+#endif // WINT_MIN
+
+#ifndef WINT_MAX
+ "WINT_MAX",
+#else
+ "",
+#endif // WINT_MAX
+
+#ifndef SIG_ATOMIC_MIN
+ "SIG_ATOMIC_MIN",
+#else
+ "",
+#endif // SIG_ATOMIC_MIN
+
+#ifndef SIG_ATOMIC_MAX
+ "SIG_ATOMIC_MAX",
+#else
+ "",
+#endif // SIG_ATOMIC_MAX
+
+ 0
+};
+
+
+static const char* const
+missing_optional_macros[] = {
+
+#ifndef UINT8_MAX
+ "UINT8_MAX",
+#else
+ "",
+#endif // UINT8_MAX
+
+#ifndef UINT16_MAX
+ "UINT16_MAX",
+#else
+ "",
+#endif // UINT16_MAX
+
+#ifndef UINT32_MAX
+ "UINT32_MAX",
+#else
+ "",
+#endif // UINT32_MAX
+
+ 0
+};
+
+
+static const char* const
+missing_64_bit_macros[] = {
+
+#ifndef INT_LEAST64_MIN
+ "INT_LEAST64_MIN",
+#else
+ "",
+#endif // INT_LEAST64_MIN
+
+#ifndef INT_FAST64_MIN
+ "INT_FAST64_MIN",
+#else
+ "",
+#endif // INT_FAST64_MIN
+
+#ifndef UINT64_MAX
+ "UINT64_MAX",
+#else
+ "",
+#endif // UINT64_MAX
+
+#ifndef INT_LEAST64_MAX
+ "INT_LEAST64_MAX",
+#else
+ "",
+#endif // INT_LEAST64_MAX
+
+#ifndef UINT_LEAST64_MAX
+ "UINT_LEAST64_MAX",
+#else
+ "",
+#endif // UINT_LEAST64_MAX
+
+#ifndef INT_FAST64_MAX
+ "INT_FAST64_MAX",
+#else
+ "",
+#endif // INT_FAST64_MAX
+
+#ifndef UINT_FAST64_MAX
+ "UINT_FAST64_MAX",
+#else
+ "",
+#endif // UINT_FAST64_MAX
+
+ 0
+};
+
+/**************************************************************************/
+
+#ifndef _RWSTD_NO_NAMESPACE
+
+// check types
+
+#define DEFINE_TYPE(name) \
+ struct name { \
+ int i_; \
+ char dummy_ [256]; \
+ \
+ name (int i = 0): i_ (i) { } \
+ operator int () const volatile { return i_; } \
+ name operator- (int i) const volatile { return i_ - i; } \
+ name operator~ () const volatile { return ~0; } \
+ name operator& (int i) const volatile { return i_ & i; } \
+ bool operator< (int i) const volatile { return i_ < i; } \
+}
+
+
+namespace Fallback {
+
+DEFINE_TYPE (int8_t);
+DEFINE_TYPE (uint8_t);
+DEFINE_TYPE (int_least8_t);
+DEFINE_TYPE (uint_least8_t);
+DEFINE_TYPE (int_fast8_t);
+DEFINE_TYPE (uint_fast8_t);
+
+DEFINE_TYPE (int16_t);
+DEFINE_TYPE (uint16_t);
+DEFINE_TYPE (int_least16_t);
+DEFINE_TYPE (uint_least16_t);
+DEFINE_TYPE (int_fast16_t);
+DEFINE_TYPE (uint_fast16_t);
+
+DEFINE_TYPE (int32_t);
+DEFINE_TYPE (uint32_t);
+DEFINE_TYPE (int_least32_t);
+DEFINE_TYPE (uint_least32_t);
+DEFINE_TYPE (int_fast32_t);
+DEFINE_TYPE (uint_fast32_t);
+
+DEFINE_TYPE (int64_t);
+DEFINE_TYPE (uint64_t);
+DEFINE_TYPE (int_least64_t);
+DEFINE_TYPE (uint_least64_t);
+DEFINE_TYPE (int_fast64_t);
+DEFINE_TYPE (uint_fast64_t);
+
+DEFINE_TYPE (intmax_t);
+DEFINE_TYPE (uintmax_t);
+
+DEFINE_TYPE (intptr_t);
+DEFINE_TYPE (uintptr_t);
+
+} // Namespace Fallback
+
+namespace std {
+
+// define test functions in namespace std to detect the presece
+// or absence of the required types
+
+namespace tr1 {
+
+namespace Nested {
+
+using namespace Fallback;
+
+// each test_xxx_t typedef aliases std::tr1::xxx_t if the corresponding
+// type is defined in namespace std::tr1, or Fallback::xxx_t otherwise
+
+typedef int8_t test_int8_t;
+typedef uint8_t test_uint8_t;
+typedef int_least8_t test_int_least8_t;
+typedef uint_least8_t test_uint_least8_t;
+typedef int_fast8_t test_int_fast8_t;
+typedef uint_fast8_t test_uint_fast8_t;
+
+typedef int16_t test_int16_t;
+typedef uint16_t test_uint16_t;
+typedef int_least16_t test_int_least16_t;
+typedef uint_least16_t test_uint_least16_t;
+typedef int_fast16_t test_int_fast16_t;
+typedef uint_fast16_t test_uint_fast16_t;
+
+typedef int32_t test_int32_t;
+typedef uint32_t test_uint32_t;
+typedef int_least32_t test_int_least32_t;
+typedef uint_least32_t test_uint_least32_t;
+typedef int_fast32_t test_int_fast32_t;
+typedef uint_fast32_t test_uint_fast32_t;
+
+typedef int64_t test_int64_t;
+typedef uint64_t test_uint64_t;
+typedef int_least64_t test_int_least64_t;
+typedef uint_least64_t test_uint_least64_t;
+typedef int_fast64_t test_int_fast64_t;
+typedef uint_fast64_t test_uint_fast64_t;
+
+typedef intmax_t test_intmax_t;
+typedef uintmax_t test_uintmax_t;
+typedef intptr_t test_intptr_t;
+typedef uintptr_t test_uintptr_t;
+
+} // namespace Nested
+
+} // namespace tr1
+
+} // namespace std
+
+typedef std::tr1::Nested::test_int8_t test_int8_t;
+typedef std::tr1::Nested::test_uint8_t test_uint8_t;
+typedef std::tr1::Nested::test_int_least8_t test_int_least8_t;
+typedef std::tr1::Nested::test_uint_least8_t test_uint_least8_t;
+typedef std::tr1::Nested::test_int_fast8_t test_int_fast8_t;
+typedef std::tr1::Nested::test_uint_fast8_t test_uint_fast8_t;
+
+typedef std::tr1::Nested::test_int16_t test_int16_t;
+typedef std::tr1::Nested::test_uint16_t test_uint16_t;
+typedef std::tr1::Nested::test_int_least16_t test_int_least16_t;
+typedef std::tr1::Nested::test_uint_least16_t test_uint_least16_t;
+typedef std::tr1::Nested::test_int_fast16_t test_int_fast16_t;
+typedef std::tr1::Nested::test_uint_fast16_t test_uint_fast16_t;
+
+typedef std::tr1::Nested::test_int32_t test_int32_t;
+typedef std::tr1::Nested::test_uint32_t test_uint32_t;
+typedef std::tr1::Nested::test_int_least32_t test_int_least32_t;
+typedef std::tr1::Nested::test_uint_least32_t test_uint_least32_t;
+typedef std::tr1::Nested::test_int_fast32_t test_int_fast32_t;
+typedef std::tr1::Nested::test_uint_fast32_t test_uint_fast32_t;
+
+typedef std::tr1::Nested::test_int64_t test_int64_t;
+typedef std::tr1::Nested::test_uint64_t test_uint64_t;
+typedef std::tr1::Nested::test_int_least64_t test_int_least64_t;
+typedef std::tr1::Nested::test_uint_least64_t test_uint_least64_t;
+typedef std::tr1::Nested::test_int_fast64_t test_int_fast64_t;
+typedef std::tr1::Nested::test_uint_fast64_t test_uint_fast64_t;
+
+typedef std::tr1::Nested::test_intmax_t test_intmax_t;
+typedef std::tr1::Nested::test_uintmax_t test_uintmax_t;
+typedef std::tr1::Nested::test_intptr_t test_intptr_t;
+typedef std::tr1::Nested::test_uintptr_t test_uintptr_t;
+
+/**************************************************************************/
+
+template <class intT>
+void test_bits (int line, // line number
+ intT testval, // tested value (for macros)
+ int expect, // expected number of bits
+ bool exact, // exactly (or at least)
+ const char *type_name, // name of type
+ const char *macro_name = 0, // name of macro
+ const char *valstr = 0) // value (for message)
+{
+ static volatile intT zero = intT (0);
+ static volatile intT one = intT (1);
+ static volatile intT minus_one = zero - one;
+ static volatile intT all_bits_set = ~zero;
+
+ const bool is_signed = minus_one < zero;
+
+ const unsigned maxbits = sizeof (intT) * _RWSTD_CHAR_BIT;
+
+ int nbits = 0;
+
+ intT maximum = one;
+ intT minimum = is_signed ? minus_one : one;
+
+ // count the number of bits
+ for (unsigned i = 0; i != maxbits; ++i) {
+
+ if (all_bits_set & (intT (1) << i))
+ ++nbits;
+ else
+ break;
+
+ maximum = maximum * intT (2);
+ minimum = maximum * intT (2);
+ }
+
+ if (macro_name) {
+ // verify macro value
+
+ if (is_signed) {
+ if (zero < testval) {
+ rw_assert (maximum <= testval, 0, line,
+ "%s >= %s", macro_name, valstr);
+ }
+ else {
+ rw_assert (testval <= minimum, 0, line,
+ "%s <= %s", macro_name, valstr);
+ }
+ }
+ else {
+ rw_assert (maximum <= testval, 0, line,
+ "%s >= %s", macro_name, valstr);
+ }
+ }
+ else {
+ if (expect < 0) {
+ expect = -expect;
+
+ // verify that the type is signed
+ rw_assert (minus_one < zero, 0, line,
+ "%s must be a signed type", type_name);
+ }
+ else {
+ // verify that the type is unsigned
+ rw_assert (zero < minus_one, 0, line,
+ "%s must be an unsigned type", type_name);
+ }
+
+ // verify that the type is exactly/at least as wide as expected
+ const bool success = exact ? expect == nbits : expect <= nbits;
+
+ if (64 != expect || !rw_opt_no_64_bit)
+ rw_assert (success, 0, 0,
+ "%s expected width %{?}exactly%{:}at least%{;} "
+ "%d bits, got %d", type_name, exact, expect, nbits);
+ }
+}
+
+/**************************************************************************/
+
+static void
+test_types ()
+{
+#define TEST_REQUIRED_TYPE(name, bits, exact) \
+ do { \
+ rw_info (0, 0, __LINE__, "std::tr1::%s (required)", # name); \
+ const bool type_defined = \
+ sizeof (test_ ## name) != sizeof (Fallback::name); \
+ rw_assert (type_defined, 0, __LINE__, \
+ "required type %s not defined in namespace " \
+ "std::tr1", #name); \
+ if (type_defined) \
+ test_bits (__LINE__, test_ ## name (0), \
+ bits, exact, #name); \
+ } while (0)
+
+#define TEST_OPTIONAL_TYPE(name, bits, exact) \
+ do { \
+ rw_info (0, 0, __LINE__, "std::tr1::%s (optional)", # name); \
+ const bool type_defined = \
+ sizeof (test_ ## name) != sizeof (Fallback::name); \
+ rw_warn (type_defined, 0, __LINE__, \
+ "optional type %s not defined in namespace " \
+ "std::tr1", #name); \
+ if (type_defined) \
+ test_bits (__LINE__, test_ ## name (0), \
+ bits, exact, #name); \
+ } while (0)
+
+ TEST_OPTIONAL_TYPE (int8_t, -8, true);
+ TEST_OPTIONAL_TYPE (uint8_t, 8, true);
+ TEST_OPTIONAL_TYPE (int16_t, -16, true);
+ TEST_OPTIONAL_TYPE (uint16_t, 16, true);
+ TEST_OPTIONAL_TYPE (int32_t, -32, true);
+ TEST_OPTIONAL_TYPE (uint32_t, 32, true);
+
+ TEST_REQUIRED_TYPE (int_least8_t, -8, false);
+ TEST_REQUIRED_TYPE (uint_least8_t, 8, false);
+ TEST_REQUIRED_TYPE (int_fast8_t, -8, false);
+ TEST_REQUIRED_TYPE (uint_fast8_t, 8, false);
+
+ TEST_REQUIRED_TYPE (int_least16_t, -16, false);
+ TEST_REQUIRED_TYPE (uint_least16_t, 16, false);
+ TEST_REQUIRED_TYPE (int_fast16_t, -16, false);
+ TEST_REQUIRED_TYPE (uint_fast16_t, 16, false);
+
+ TEST_REQUIRED_TYPE (int_least32_t, -32, false);
+ TEST_REQUIRED_TYPE (uint_least32_t, 32, false);
+ TEST_REQUIRED_TYPE (int_fast32_t, -32, false);
+ TEST_REQUIRED_TYPE (uint_fast32_t, 32, false);
+
+ TEST_REQUIRED_TYPE (intmax_t, -64, false);
+ TEST_REQUIRED_TYPE (uintmax_t, 64, false);
+ TEST_REQUIRED_TYPE (intptr_t, -16, false);
+ TEST_REQUIRED_TYPE (uintptr_t, 16, false);
+
+ if (rw_opt_no_64_bit) {
+ rw_note (0, 0, 0, "tests of 64-bit types disabled");
+ }
+ else {
+ TEST_OPTIONAL_TYPE (int64_t, -64, true);
+ TEST_OPTIONAL_TYPE (uint64_t, 64, true);
+
+ TEST_REQUIRED_TYPE (int_least64_t, -64, false);
+ TEST_REQUIRED_TYPE (uint_least64_t, 64, false);
+ TEST_REQUIRED_TYPE (int_fast64_t, -64, false);
+ TEST_REQUIRED_TYPE (uint_fast64_t, 64, false);
+ }
+}
+
+#else // if defined (_RWSTD_NO_NAMESPACE)
+
+static void
+test_types ()
+{
+ rw_note (0, 0, 0, "_RWSTD_NO_NAMESPACE defined, cannot test");
+}
+
+#endif // _RWSTD_NO_NAMESPACE
+
+/**************************************************************************/
+
+static void
+test_macros ()
+{
+ for (unsigned i = 0; missing_macros [i]; ++i) {
+ rw_assert ('\0' == missing_macros [i][0], 0, __LINE__,
+ "required macro %s not defined",
+ missing_macros [i]);
+ }
+
+#define TEST_MACRO(T, macro, bits, exact, valstr) \
+ test_bits (__LINE__, test_ ## T (macro), bits, exact, #T, #macro, valstr)
+
+ TEST_MACRO (int_least8_t, INT_LEAST8_MIN, -8, true, "-127");
+ TEST_MACRO (int_least8_t, INT_LEAST8_MAX, -8, true, "+127");
+ TEST_MACRO (uint_least8_t, UINT_LEAST8_MAX, 8, true, "256");
+
+ TEST_MACRO (int_fast8_t, INT_FAST8_MIN, -8, true, "-127");
+ TEST_MACRO (int_fast8_t, INT_FAST8_MAX, -8, true, "+127");
+ TEST_MACRO (uint_fast8_t, UINT_FAST8_MAX, 8, true, "256");
+
+ TEST_MACRO (int_least16_t, INT_LEAST16_MIN, -16, true, "-32767");
+ TEST_MACRO (int_least16_t, INT_LEAST16_MAX, -16, true, "+32767");
+ TEST_MACRO (uint_least16_t, UINT_LEAST16_MAX, 16, true, "65535");
+
+ TEST_MACRO (int_fast16_t, INT_FAST16_MIN, -16, true, "-32767");
+ TEST_MACRO (int_fast16_t, INT_FAST16_MAX, -16, true, "+32767");
+ TEST_MACRO (uint_fast16_t, UINT_FAST16_MAX, 16, true, "65535");
+
+ TEST_MACRO (int_least32_t, INT_LEAST32_MIN, -32, true, "-2147483647");
+ TEST_MACRO (int_least32_t, INT_LEAST32_MAX, -32, true, "+2147483647");
+ TEST_MACRO (uint_least32_t, UINT_LEAST32_MAX, 32, true, "4294967295");
+
+ TEST_MACRO (int_fast32_t, INT_FAST32_MIN, -32, true, "-2147483647");
+ TEST_MACRO (int_fast32_t, INT_FAST32_MAX, -32, true, "+2147483647");
+ TEST_MACRO (uint_fast32_t, UINT_FAST32_MAX, 32, true, "4294967295");
+
+#define TEST_MACRO_NO_TYPE(macro, bits, exact, valstr) \
+ test_bits (__LINE__, macro, bits, exact, "", #macro, valstr)
+
+ TEST_MACRO_NO_TYPE (PTRDIFF_MIN, 16, false, "-65535");
+ TEST_MACRO_NO_TYPE (PTRDIFF_MAX, 16, false, "+65535");
+
+ TEST_MACRO_NO_TYPE (SIZE_MAX, 16, false, "+65535");
+
+ TEST_MACRO_NO_TYPE (SIG_ATOMIC_MIN, 8, false, "-127");
+ TEST_MACRO_NO_TYPE (SIG_ATOMIC_MAX, 8, false, "+127");
+
+ TEST_MACRO_NO_TYPE (WCHAR_MIN, 8, false, "-127");
+ TEST_MACRO_NO_TYPE (WCHAR_MAX, 8, false, "+127");
+
+ TEST_MACRO_NO_TYPE (WINT_MIN, 16, false, "-32767");
+ TEST_MACRO_NO_TYPE (WINT_MAX, 16, false, "+32768");
+
+
+ for (unsigned i = 0; missing_optional_macros [i]; ++i) {
+ rw_warn ('\0' == missing_optional_macros [i][0], 0, __LINE__,
+ "optional macro %s not defined",
+ missing_optional_macros [i]);
+ }
+
+ TEST_MACRO (int8_t, INT8_MIN, -8, true, "-128");
+ TEST_MACRO (int8_t, INT8_MAX, -8, true, "127");
+ TEST_MACRO (uint8_t, UINT8_MAX, 8, true, "256");
+
+ TEST_MACRO (int16_t, INT16_MIN, -16, true, "-32768");
+ TEST_MACRO (int16_t, INT16_MAX, -16, true, "32767");
+ TEST_MACRO (uint16_t, UINT16_MAX, 16, true, "65535");
+
+ TEST_MACRO (int32_t, INT32_MIN, -32, true, "-2147483648");
+ TEST_MACRO (int32_t, INT32_MAX, -32, true, "2147483647");
+ TEST_MACRO (uint32_t, UINT32_MAX, 32, true, "4294967295");
+
+ if (rw_opt_no_64_bit) {
+ rw_note (0, 0, 0, "tests of 64-bit macros disabled");
+ }
+ else {
+ for (unsigned i = 0; missing_64_bit_macros [i]; ++i) {
+ rw_assert ('\0' == missing_64_bit_macros [i][0], 0, __LINE__,
+ "required macro %s not defined",
+ missing_64_bit_macros [i]);
+ }
+
+ TEST_MACRO (int64_t, INT64_MIN, -64, true, "?");
+ TEST_MACRO (int64_t, INT64_MAX, -64, true, "?");
+ TEST_MACRO (uint64_t, UINT64_MAX, 64, true, "?");
+
+ TEST_MACRO (int_least64_t, INT_LEAST64_MIN, -64, true, "?");
+ TEST_MACRO (int_least64_t, INT_LEAST64_MAX, -64, true, "?");
+ TEST_MACRO (uint_least64_t, UINT_LEAST64_MAX, 64, true, "?");
+
+ TEST_MACRO (int_fast64_t, INT_FAST64_MIN, -64, true, "?");
+ TEST_MACRO (int_fast64_t, INT_FAST64_MAX, -64, true, "?");
+ TEST_MACRO (uint_fast64_t, UINT_FAST64_MAX, 64, true, "?");
+ }
+}
+
+/**************************************************************************/
+
+static int
+run_test (int, char*[])
+{
+ test_types ();
+
+ test_macros ();
+
+ return 0;
+}
+
+/**************************************************************************/
+
+int main (int argc, char *argv[])
+{
+ return rw_test (argc, argv, __FILE__,
+ "tr.c99.cstdint",
+ 0 /* no comment */,
+ run_test,
+ "|-no-macros# "
+ "|-no-types# "
+ "|-no-64-bit#",
+ &rw_opt_no_macros,
+ &rw_opt_no_types,
+ &rw_opt_no_64_bit);
+}
Propchange: incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/stdcxx/trunk/tests/tr1.c99/8.cstdint.cpp
------------------------------------------------------------------------------
svn:keywords = Id