gettimeofday: port recent C++ fix to Emacs
[gnulib.git] / tests / test-stdint.c
index a2f8f8e..1c559b0 100644 (file)
@@ -1,31 +1,26 @@
 /* Test of <stdint.h> substitute.
-   Copyright (C) 2006 Free Software Foundation, Inc.
+   Copyright (C) 2006-2013 Free Software Foundation, Inc.
 
-   This program is free software; you can redistribute it and/or modify it
-   under the terms of the GNU Library General Public License as published
-   by the Free Software Foundation; either version 2, or (at your option)
-   any later version.
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Library General Public License for more details.
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
 
-   You should have received a copy of the GNU Library General Public
-   License along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
-   USA.  */
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 /* Written by Bruno Haible <bruno@clisp.org>, 2006.  */
 
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
+#include <config.h>
 
 /* Whether to enable pedantic checks. */
 #define DO_PEDANTIC 0
 
-#define __STDC_LIMIT_MACROS 1 /* to make it work also in C++ mode */
 #include <stdint.h>
 
 #include "verify.h"
@@ -38,7 +33,7 @@
 # define _verify_func(line) _verify_func2(line)
 # define _verify_func2(line) verify_func_ ## line
 #else
-# define verify_same_types(expr1,expr2)
+# define verify_same_types(expr1,expr2) extern void verify_func (int)
 #endif
 
 /* 7.18.1.1. Exact-width integer types */
@@ -62,7 +57,7 @@ verify (TYPE_MAXIMUM (int32_t) == INT32_MAX);
 verify_same_types (INT32_MIN, (int32_t) 0 + 0);
 verify_same_types (INT32_MAX, (int32_t) 0 + 0);
 
-#if HAVE_INT64_T_IN_STDINT_H || _STDINT_H_HAVE_INT64
+#ifdef INT64_MAX
 int64_t a4[3] = { INT64_C (17), INT64_MIN, INT64_MAX };
 verify (TYPE_MINIMUM (int64_t) == INT64_MIN);
 verify (TYPE_MAXIMUM (int64_t) == INT64_MAX);
@@ -82,7 +77,7 @@ uint32_t b3[2] = { UINT32_C (17), UINT32_MAX };
 verify (TYPE_MAXIMUM (uint32_t) == UINT32_MAX);
 verify_same_types (UINT32_MAX, (uint32_t) 0 + 0);
 
-#if HAVE_UINT64_T_IN_STDINT_H || _STDINT_H_HAVE_UINT64
+#ifdef UINT64_MAX
 uint64_t b4[2] = { UINT64_C (17), UINT64_MAX };
 verify (TYPE_MAXIMUM (uint64_t) == UINT64_MAX);
 verify_same_types (UINT64_MAX, (uint64_t) 0 + 0);
@@ -121,7 +116,7 @@ verify (TYPE_MAXIMUM (int_least32_t) == INT_LEAST32_MAX);
 verify_same_types (INT_LEAST32_MIN, (int_least32_t) 0 + 0);
 verify_same_types (INT_LEAST32_MAX, (int_least32_t) 0 + 0);
 
-#if HAVE_INT_LEAST64_T_IN_STDINT_H || _STDINT_H_HAVE_INT64
+#ifdef INT_LEAST64_MAX
 int_least64_t c4[3] = { 17, INT_LEAST64_MIN, INT_LEAST64_MAX };
 verify (TYPE_MINIMUM (int_least64_t) == INT_LEAST64_MIN);
 verify (TYPE_MAXIMUM (int_least64_t) == INT_LEAST64_MAX);
@@ -141,7 +136,7 @@ uint_least32_t d3[2] = { 17, UINT_LEAST32_MAX };
 verify (TYPE_MAXIMUM (uint_least32_t) == UINT_LEAST32_MAX);
 verify_same_types (UINT_LEAST32_MAX, (uint_least32_t) 0 + 0);
 
-#if HAVE_UINT_LEAST64_T_IN_STDINT_H || _STDINT_H_HAVE_UINT64
+#ifdef UINT_LEAST64_MAX
 uint_least64_t d4[2] = { 17, UINT_LEAST64_MAX };
 verify (TYPE_MAXIMUM (uint_least64_t) == UINT_LEAST64_MAX);
 verify_same_types (UINT_LEAST64_MAX, (uint_least64_t) 0 + 0);
@@ -180,7 +175,7 @@ verify (TYPE_MAXIMUM (int_fast32_t) == INT_FAST32_MAX);
 verify_same_types (INT_FAST32_MIN, (int_fast32_t) 0 + 0);
 verify_same_types (INT_FAST32_MAX, (int_fast32_t) 0 + 0);
 
-#if HAVE_INT_FAST64_T_IN_STDINT_H || _STDINT_H_HAVE_INT64
+#ifdef INT_FAST64_MAX
 int_fast64_t e4[3] = { 17, INT_FAST64_MIN, INT_FAST64_MAX };
 verify (TYPE_MINIMUM (int_fast64_t) == INT_FAST64_MIN);
 verify (TYPE_MAXIMUM (int_fast64_t) == INT_FAST64_MAX);
@@ -200,7 +195,7 @@ uint_fast32_t f3[2] = { 17, UINT_FAST32_MAX };
 verify (TYPE_MAXIMUM (uint_fast32_t) == UINT_FAST32_MAX);
 verify_same_types (UINT_FAST32_MAX, (uint_fast32_t) 0 + 0);
 
-#if HAVE_UINT_FAST64_T_IN_STDINT_H || _STDINT_H_HAVE_UINT64
+#ifdef UINT_FAST64_MAX
 uint_fast64_t f4[2] = { 17, UINT_FAST64_MAX };
 verify (TYPE_MAXIMUM (uint_fast64_t) == UINT_FAST64_MAX);
 verify_same_types (UINT_FAST64_MAX, (uint_fast64_t) 0 + 0);
@@ -250,11 +245,15 @@ uintmax_t j[2] = { UINTMAX_C (17), UINTMAX_MAX };
 verify (TYPE_MAXIMUM (uintmax_t) == UINTMAX_MAX);
 verify_same_types (UINTMAX_MAX, (uintmax_t) 0 + 0);
 
+/* As of 2007, Sun C and HP-UX 10.20 cc don't support 'long long' constants in
+   the preprocessor.  */
+#if !(defined __SUNPRO_C || (defined __hpux && !defined __GNUC__))
 #if INTMAX_MIN && INTMAX_MAX && UINTMAX_MAX
 /* ok */
 #else
 err or;
 #endif
+#endif
 
 /* 7.18.3. Limits of other integer types */
 
@@ -293,74 +292,68 @@ verify_same_types (SIZE_MAX, (size_t) 0 + 0);
 err or;
 #endif
 
+#if HAVE_WCHAR_T
 verify (TYPE_MINIMUM (wchar_t) == WCHAR_MIN);
 verify (TYPE_MAXIMUM (wchar_t) == WCHAR_MAX);
 verify_same_types (WCHAR_MIN, (wchar_t) 0 + 0);
 verify_same_types (WCHAR_MAX, (wchar_t) 0 + 0);
 
-#if WCHAR_MIN != 17 && WCHAR_MAX
+# if WCHAR_MIN != 17 && WCHAR_MAX
 /* ok */
-#else
+# else
 err or;
+# endif
 #endif
 
-#include <stdio.h>
-#include <time.h>
-#include <wchar.h>
+#if HAVE_WINT_T
+# include <wchar.h>
 
 verify (TYPE_MINIMUM (wint_t) == WINT_MIN);
 verify (TYPE_MAXIMUM (wint_t) == WINT_MAX);
 verify_same_types (WINT_MIN, (wint_t) 0 + 0);
 verify_same_types (WINT_MAX, (wint_t) 0 + 0);
 
-#if WINT_MIN != 17 && WINT_MAX
+# if WINT_MIN != 17 && WINT_MAX
 /* ok */
-#else
+# else
 err or;
+# endif
 #endif
 
 /* 7.18.4. Macros for integer constants */
 
 verify (INT8_C (17) == 17);
-#if 0 /* The language in ISO C 99 7.18.4 is too strong. */
-verify_same_types (INT8_C (17), (int_least8_t)0);
-#endif
+verify_same_types (INT8_C (17), (int_least8_t)0 + 0);
 verify (UINT8_C (17) == 17);
-#if 0 /* The language in ISO C 99 7.18.4 is too strong. */
-verify_same_types (UINT8_C (17), (uint_least8_t)0);
-#endif
+verify_same_types (UINT8_C (17), (uint_least8_t)0 + 0);
 
 verify (INT16_C (17) == 17);
-#if 0 /* The language in ISO C 99 7.18.4 is too strong. */
-verify_same_types (INT16_C (17), (int_least16_t)0);
-#endif
+verify_same_types (INT16_C (17), (int_least16_t)0 + 0);
 verify (UINT16_C (17) == 17);
-#if 0 /* The language in ISO C 99 7.18.4 is too strong. */
-verify_same_types (UINT16_C (17), (uint_least16_t)0);
-#endif
+verify_same_types (UINT16_C (17), (uint_least16_t)0 + 0);
 
 verify (INT32_C (17) == 17);
-verify_same_types (INT32_C (17), (int_least32_t)0);
+verify_same_types (INT32_C (17), (int_least32_t)0 + 0);
 verify (UINT32_C (17) == 17);
-verify_same_types (UINT32_C (17), (uint_least32_t)0);
+verify_same_types (UINT32_C (17), (uint_least32_t)0 + 0);
 
-#if HAVE_INT_LEAST64_T_IN_STDINT_H || _STDINT_H_HAVE_INT64
+#ifdef INT64_C
 verify (INT64_C (17) == 17);
-verify_same_types (INT64_C (17), (int_least64_t)0);
+verify_same_types (INT64_C (17), (int_least64_t)0 + 0);
 #endif
-#if HAVE_UINT_LEAST64_T_IN_STDINT_H || _STDINT_H_HAVE_UINT64
+#ifdef UINT64_C
 verify (UINT64_C (17) == 17);
-verify_same_types (UINT64_C (17), (uint_least64_t)0);
+verify_same_types (UINT64_C (17), (uint_least64_t)0 + 0);
 #endif
 
 verify (INTMAX_C (17) == 17);
-verify_same_types (INTMAX_C (17), (intmax_t)0);
+verify_same_types (INTMAX_C (17), (intmax_t)0 + 0);
 verify (UINTMAX_C (17) == 17);
-verify_same_types (UINTMAX_C (17), (uintmax_t)0);
+verify_same_types (UINTMAX_C (17), (uintmax_t)0 + 0);
 
 
 int
-main ()
+main (void)
 {
   return 0;
 }