bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* stdint.h, C++ and __STDC_LIMIT_MACROS
@ 2015-11-01 17:37 Pedro Alves
  2015-11-02  1:36 ` Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-01 17:37 UTC (permalink / raw
  To: bug-gnulib

[-- Attachment #1: Type: text/plain, Size: 2253 bytes --]

Hello,

I'm working on porting GDB to C++03, and cross building for --host=x86_64-w64-mingw32 using
Fedora 20's g++ (gcc version 4.8.4 20141219 (Fedora MinGW 4.8.4-1.fc20)), I'm stumbling on:

 In file included from ../../src/gdb/../include/splay-tree.h:43:0,
                  from ../../src/gdb/dcache.c:26:
 build-gnulib/import/inttypes.h:61:3: error: #error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
  # error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
    ^
 make: *** [dcache.o] Error 1

That's:

 #if !(INT_MIN == INT32_MIN && INT_MAX == INT32_MAX)
 # error "This file assumes that 'int' has exactly 32 bits. Please report your platform and compiler to <bug-gnulib@gnu.org>."
 #endif

The fixed inttypes.h includes stdint.h, however mingw's stdint.h requires
defining __STDC_LIMIT_MACROS:

 /* 7.18.2  Limits of specified-width integer types */
 #if !defined(__cplusplus) || defined(__STDC_LIMIT_MACROS) ||	\
     defined(__GXX_EXPERIMENTAL_CXX0X__) || __cplusplus >= 201103L

 /* 7.18.2.1  Limits of exact-width integer types */
 #define INT8_MIN (-128)
 #define INT16_MIN (-32768)
 #define INT32_MIN (-2147483647 - 1)
 #define INT64_MIN  (-9223372036854775807LL - 1)
 (...)

and gnulib is deciding that the system's stdint.h is good enough
At least, I don't get a stdint.h replacement.  I do get an inttypes.h
replacement.

I'm pulling in the stdint and inttypes modules, and do AC_LANG_PUSH([C++])
before gl_EARLY -- in config.log I see autoconf is running tests with g++.

https://www.gnu.org/software/gnulib/manual/html_node/stdint_002eh.html
says:

" Portability problems fixed by Gnulib:
 (...)
 On some hosts that predate C++11, when using C++ one must
 define __STDC_CONSTANT_MACROS to make visible the definitions of constant macros
 such as INTMAX_C, and one must define __STDC_LIMIT_MACROS to make visible the
 definitions of limit macros such as INTMAX_MAX. "

I can work around this by defining __STDC_LIMIT_MACROS in gdb before
including stdint.h, but it sounds like I shouldn't need to.  Thus I wonder
what am I missing.

I'm attaching a gzip'ed config.log.

Thanks,
Pedro Alves

[-- Attachment #2: config.log.gz --]
[-- Type: application/gzip, Size: 45299 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-01 17:37 stdint.h, C++ and __STDC_LIMIT_MACROS Pedro Alves
@ 2015-11-02  1:36 ` Paul Eggert
  2015-11-02 10:36   ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Eggert @ 2015-11-02  1:36 UTC (permalink / raw
  To: Pedro Alves, bug-gnulib

Pedro Alves wrote:
> and gnulib is deciding that the system's stdint.h is good enough
> At least, I don't get a stdint.h replacement.

Since gnulib's test program contains this:

intmax_t i = INTMAX_MAX;

I'm surprised that gnulib decided that the system's stdint.h was good enough. 
Perhaps you could investigate why.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-02  1:36 ` Paul Eggert
@ 2015-11-02 10:36   ` Pedro Alves
  2015-11-02 11:03     ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-02 10:36 UTC (permalink / raw
  To: Paul Eggert, bug-gnulib

On 11/02/2015 01:36 AM, Paul Eggert wrote:
> Pedro Alves wrote:
>> and gnulib is deciding that the system's stdint.h is good enough
>> At least, I don't get a stdint.h replacement.
> 
> Since gnulib's test program contains this:
> 
> intmax_t i = INTMAX_MAX;
> 
> I'm surprised that gnulib decided that the system's stdint.h was good enough. 
> Perhaps you could investigate why.
> 

Thanks Paul.

AFAICS, that doesn't compile, the test fails, but I still don't
get a replacement.  config.log has this:

~~~
conftest.cpp:150:14: error: 'INTMAX_MAX' was not declared in this scope
 intmax_t i = INTMAX_MAX;
              ^
~~~

See here the whole context of the stdint.h test:

~~~
configure:8818: checking whether stdint.h conforms to C99
configure:8987: x86_64-w64-mingw32-g++ -c -g -O2  conftest.cpp >&5
conftest.cpp:66:2: error: #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
 #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
  ^
conftest.cpp:100:50: error: size of array 'b1' is negative
 typedef int b1[(unsigned char) -1 != 255 ? 1 : -1];
                                                  ^
conftest.cpp:111:31: error: 'INT8_C' was not declared in this scope
 int_least8_t c1 = INT8_C (0x7f);
                               ^
conftest.cpp:112:22: error: 'INT_LEAST8_MAX' was not declared in this scope
 int_least8_t c1max = INT_LEAST8_MAX;
                      ^
conftest.cpp:113:22: error: 'INT_LEAST8_MIN' was not declared in this scope
 int_least8_t c1min = INT_LEAST8_MIN;
                      ^
conftest.cpp:114:35: error: 'INT16_C' was not declared in this scope
 int_least16_t c2 = INT16_C (0x7fff);
                                   ^
conftest.cpp:115:23: error: 'INT_LEAST16_MAX' was not declared in this scope
 int_least16_t c2max = INT_LEAST16_MAX;
                       ^
conftest.cpp:116:23: error: 'INT_LEAST16_MIN' was not declared in this scope
 int_least16_t c2min = INT_LEAST16_MIN;
                       ^
conftest.cpp:117:39: error: 'INT32_C' was not declared in this scope
 int_least32_t c3 = INT32_C (0x7fffffff);
                                       ^
conftest.cpp:118:23: error: 'INT_LEAST32_MAX' was not declared in this scope
 int_least32_t c3max = INT_LEAST32_MAX;
                       ^
conftest.cpp:119:23: error: 'INT_LEAST32_MIN' was not declared in this scope
 int_least32_t c3min = INT_LEAST32_MIN;
                       ^
conftest.cpp:120:47: error: 'INT64_C' was not declared in this scope
 int_least64_t c4 = INT64_C (0x7fffffffffffffff);
                                               ^
conftest.cpp:121:23: error: 'INT_LEAST64_MAX' was not declared in this scope
 int_least64_t c4max = INT_LEAST64_MAX;
                       ^
conftest.cpp:122:23: error: 'INT_LEAST64_MIN' was not declared in this scope
 int_least64_t c4min = INT_LEAST64_MIN;
                       ^
conftest.cpp:123:33: error: 'UINT8_C' was not declared in this scope
 uint_least8_t d1 = UINT8_C (0xff);
                                 ^
conftest.cpp:124:23: error: 'UINT_LEAST8_MAX' was not declared in this scope
 uint_least8_t d1max = UINT_LEAST8_MAX;
                       ^
conftest.cpp:125:37: error: 'UINT16_C' was not declared in this scope
 uint_least16_t d2 = UINT16_C (0xffff);
                                     ^
conftest.cpp:126:24: error: 'UINT_LEAST16_MAX' was not declared in this scope
 uint_least16_t d2max = UINT_LEAST16_MAX;
                        ^
conftest.cpp:127:41: error: 'UINT32_C' was not declared in this scope
 uint_least32_t d3 = UINT32_C (0xffffffff);
                                         ^
conftest.cpp:128:24: error: 'UINT_LEAST32_MAX' was not declared in this scope
 uint_least32_t d3max = UINT_LEAST32_MAX;
                        ^
conftest.cpp:129:49: error: 'UINT64_C' was not declared in this scope
 uint_least64_t d4 = UINT64_C (0xffffffffffffffff);
                                                 ^
conftest.cpp:130:24: error: 'UINT_LEAST64_MAX' was not declared in this scope
 uint_least64_t d4max = UINT_LEAST64_MAX;
                        ^
conftest.cpp:131:18: error: 'INT_FAST8_MAX' was not declared in this scope
 int_fast8_t e1 = INT_FAST8_MAX;
                  ^
conftest.cpp:132:21: error: 'INT_FAST8_MIN' was not declared in this scope
 int_fast8_t e1min = INT_FAST8_MIN;
                     ^
conftest.cpp:133:19: error: 'INT_FAST16_MAX' was not declared in this scope
 int_fast16_t e2 = INT_FAST16_MAX;
                   ^
conftest.cpp:134:22: error: 'INT_FAST16_MIN' was not declared in this scope
 int_fast16_t e2min = INT_FAST16_MIN;
                      ^
conftest.cpp:135:19: error: 'INT_FAST32_MAX' was not declared in this scope
 int_fast32_t e3 = INT_FAST32_MAX;
                   ^
conftest.cpp:136:22: error: 'INT_FAST32_MIN' was not declared in this scope
 int_fast32_t e3min = INT_FAST32_MIN;
                      ^
conftest.cpp:137:19: error: 'INT_FAST64_MAX' was not declared in this scope
 int_fast64_t e4 = INT_FAST64_MAX;
                   ^
conftest.cpp:138:22: error: 'INT_FAST64_MIN' was not declared in this scope
 int_fast64_t e4min = INT_FAST64_MIN;
                      ^
conftest.cpp:139:19: error: 'UINT_FAST8_MAX' was not declared in this scope
 uint_fast8_t f1 = UINT_FAST8_MAX;
                   ^
conftest.cpp:140:20: error: 'UINT_FAST16_MAX' was not declared in this scope
 uint_fast16_t f2 = UINT_FAST16_MAX;
                    ^
conftest.cpp:141:20: error: 'UINT_FAST32_MAX' was not declared in this scope
 uint_fast32_t f3 = UINT_FAST32_MAX;
                    ^
conftest.cpp:142:20: error: 'UINT_FAST64_MAX' was not declared in this scope
 uint_fast64_t f4 = UINT_FAST64_MAX;
                    ^
conftest.cpp:150:14: error: 'INTMAX_MAX' was not declared in this scope
 intmax_t i = INTMAX_MAX;
              ^
conftest.cpp:151:15: error: 'UINTMAX_MAX' was not declared in this scope
 uintmax_t j = UINTMAX_MAX;
               ^
conftest.cpp:158:7: error: 'PTRDIFF_MIN' was not declared in this scope
       PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
       ^
conftest.cpp:159:10: error: 'PTRDIFF_MAX' was not declared in this scope
       && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
          ^
conftest.cpp:163:7: error: 'SIG_ATOMIC_MIN' was not declared in this scope
       SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
       ^
conftest.cpp:164:10: error: 'SIG_ATOMIC_MAX' was not declared in this scope
       && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
          ^
conftest.cpp:173:7: error: 'WINT_MIN' was not declared in this scope
       WINT_MIN == TYPE_MINIMUM (wint_t)
       ^
conftest.cpp:174:10: error: 'WINT_MAX' was not declared in this scope
       && WINT_MAX == TYPE_MAXIMUM (wint_t)
          ^
conftest.cpp:179:25: error: a function call cannot appear in a constant-expression
         (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1;
                         ^
conftest.cpp:181:26: error: a function call cannot appear in a constant-expression
         (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1;
                          ^
conftest.cpp:196:48: error: 'UINT_LEAST8_MAX' was not declared in this scope
   int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1;
                                                ^
conftest.cpp:197:50: error: 'UINT_LEAST16_MAX' was not declared in this scope
   int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1;
                                                  ^
conftest.cpp:198:50: error: 'UINT_LEAST32_MAX' was not declared in this scope
   int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1;
                                                  ^
conftest.cpp:199:50: error: 'UINT_LEAST64_MAX' was not declared in this scope
   int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1;
                                                  ^
conftest.cpp:200:46: error: 'UINT_FAST8_MAX' was not declared in this scope
   int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1;
                                              ^
conftest.cpp:201:48: error: 'UINT_FAST16_MAX' was not declared in this scope
   int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1;
                                                ^
conftest.cpp:202:48: error: 'UINT_FAST32_MAX' was not declared in this scope
   int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1;
                                                ^
conftest.cpp:203:48: error: 'UINT_FAST64_MAX' was not declared in this scope
   int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1;
                                                ^
conftest.cpp:204:40: error: 'UINTPTR_MAX' was not declared in this scope
   int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1;
                                        ^
conftest.cpp:205:40: error: 'UINTMAX_MAX' was not declared in this scope
   int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1;
                                        ^
configure:8987: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME ""
| #define PACKAGE_TARNAME ""
| #define PACKAGE_VERSION ""
| #define PACKAGE_STRING ""
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define __EXTENSIONS__ 1
| #define _ALL_SOURCE 1
| #define _DARWIN_C_SOURCE 1
| #define _GNU_SOURCE 1
| #define __USE_MINGW_ANSI_STDIO 1
| #define _POSIX_PTHREAD_SEMANTICS 1
| #define _TANDEM_SOURCE 1
| #define _FILE_OFFSET_BITS 64
| #define _DARWIN_USE_64_BIT_INODE 1
| #define HAVE_ALLOCA 1
| #define HAVE_GETCWD 1
| #define HAVE_BTOWC 1
| #define HAVE_ISBLANK 1
| #define HAVE_ISWCTYPE 1
| #define HAVE_MBSRTOWCS 1
| #define HAVE_MEMPCPY 1
| #define HAVE_WMEMCHR 1
| #define HAVE_WMEMCPY 1
| #define HAVE_WMEMPCPY 1
| #define HAVE_GETTIMEOFDAY 1
| #define HAVE_MBSINIT 1
| #define HAVE_MBRTOWC 1
| #define HAVE_MPROTECT 1
| #define HAVE_ISWCNTRL 1
| #define HAVE_SYS_PARAM_H 1
| #define HAVE_DIRENT_H 1
| #define HAVE_WCTYPE_H 1
| #define HAVE_SYS_TIME_H 1
| #define HAVE_WCHAR_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_MATH_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_MBSTATE_T 1
| #define HAVE_DECL_ALARM 0
| #define restrict /**/
| #define HAVE_WINSOCK2_H 1
| #define HAVE_RAW_DECL_GETTIMEOFDAY 1
| #define HAVE_UNSIGNED_LONG_LONG_INT 1
| #define HAVE_LONG_LONG_INT 1
| /* end confdefs.h.  */
|
|
| #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
| #include <stdint.h>
| /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>.  */
| #if !(defined WCHAR_MIN && defined WCHAR_MAX)
| #error "WCHAR_MIN, WCHAR_MAX not defined in <stdint.h>"
| #endif
|
|
|   /* BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
|      included before <wchar.h>.  */
|   #include <stddef.h>
|   #include <signal.h>
|   #if HAVE_WCHAR_H
|   # include <stdio.h>
|   # include <time.h>
|   # include <wchar.h>
|   #endif
|
|
| #ifdef INT8_MAX
| int8_t a1 = INT8_MAX;
| int8_t a1min = INT8_MIN;
| #endif
| #ifdef INT16_MAX
| int16_t a2 = INT16_MAX;
| int16_t a2min = INT16_MIN;
| #endif
| #ifdef INT32_MAX
| int32_t a3 = INT32_MAX;
| int32_t a3min = INT32_MIN;
| #endif
| #ifdef INT64_MAX
| int64_t a4 = INT64_MAX;
| int64_t a4min = INT64_MIN;
| #endif
| #ifdef UINT8_MAX
| uint8_t b1 = UINT8_MAX;
| #else
| typedef int b1[(unsigned char) -1 != 255 ? 1 : -1];
| #endif
| #ifdef UINT16_MAX
| uint16_t b2 = UINT16_MAX;
| #endif
| #ifdef UINT32_MAX
| uint32_t b3 = UINT32_MAX;
| #endif
| #ifdef UINT64_MAX
| uint64_t b4 = UINT64_MAX;
| #endif
| int_least8_t c1 = INT8_C (0x7f);
| int_least8_t c1max = INT_LEAST8_MAX;
| int_least8_t c1min = INT_LEAST8_MIN;
| int_least16_t c2 = INT16_C (0x7fff);
| int_least16_t c2max = INT_LEAST16_MAX;
| int_least16_t c2min = INT_LEAST16_MIN;
| int_least32_t c3 = INT32_C (0x7fffffff);
| int_least32_t c3max = INT_LEAST32_MAX;
| int_least32_t c3min = INT_LEAST32_MIN;
| int_least64_t c4 = INT64_C (0x7fffffffffffffff);
| int_least64_t c4max = INT_LEAST64_MAX;
| int_least64_t c4min = INT_LEAST64_MIN;
| uint_least8_t d1 = UINT8_C (0xff);
| uint_least8_t d1max = UINT_LEAST8_MAX;
| uint_least16_t d2 = UINT16_C (0xffff);
| uint_least16_t d2max = UINT_LEAST16_MAX;
| uint_least32_t d3 = UINT32_C (0xffffffff);
| uint_least32_t d3max = UINT_LEAST32_MAX;
| uint_least64_t d4 = UINT64_C (0xffffffffffffffff);
| uint_least64_t d4max = UINT_LEAST64_MAX;
| int_fast8_t e1 = INT_FAST8_MAX;
| int_fast8_t e1min = INT_FAST8_MIN;
| int_fast16_t e2 = INT_FAST16_MAX;
| int_fast16_t e2min = INT_FAST16_MIN;
| int_fast32_t e3 = INT_FAST32_MAX;
| int_fast32_t e3min = INT_FAST32_MIN;
| int_fast64_t e4 = INT_FAST64_MAX;
| int_fast64_t e4min = INT_FAST64_MIN;
| uint_fast8_t f1 = UINT_FAST8_MAX;
| uint_fast16_t f2 = UINT_FAST16_MAX;
| uint_fast32_t f3 = UINT_FAST32_MAX;
| uint_fast64_t f4 = UINT_FAST64_MAX;
| #ifdef INTPTR_MAX
| intptr_t g = INTPTR_MAX;
| intptr_t gmin = INTPTR_MIN;
| #endif
| #ifdef UINTPTR_MAX
| uintptr_t h = UINTPTR_MAX;
| #endif
| intmax_t i = INTMAX_MAX;
| uintmax_t j = UINTMAX_MAX;
|
| #include <limits.h> /* for CHAR_BIT */
| #define TYPE_MINIMUM(t)   ((t) ((t) 0 < (t) -1 ? (t) 0 : ~ TYPE_MAXIMUM (t)))
| #define TYPE_MAXIMUM(t)   ((t) ((t) 0 < (t) -1         ? (t) -1         : ((((t) 1 << (sizeof (t) * CHAR_BIT - 2)) - 1) * 2 + 1)))
| struct s {
|   int check_PTRDIFF:
|       PTRDIFF_MIN == TYPE_MINIMUM (ptrdiff_t)
|       && PTRDIFF_MAX == TYPE_MAXIMUM (ptrdiff_t)
|       ? 1 : -1;
|   /* Detect bug in FreeBSD 6.0 / ia64.  */
|   int check_SIG_ATOMIC:
|       SIG_ATOMIC_MIN == TYPE_MINIMUM (sig_atomic_t)
|       && SIG_ATOMIC_MAX == TYPE_MAXIMUM (sig_atomic_t)
|       ? 1 : -1;
|   int check_SIZE: SIZE_MAX == TYPE_MAXIMUM (size_t) ? 1 : -1;
|   int check_WCHAR:
|       WCHAR_MIN == TYPE_MINIMUM (wchar_t)
|       && WCHAR_MAX == TYPE_MAXIMUM (wchar_t)
|       ? 1 : -1;
|   /* Detect bug in mingw.  */
|   int check_WINT:
|       WINT_MIN == TYPE_MINIMUM (wint_t)
|       && WINT_MAX == TYPE_MAXIMUM (wint_t)
|       ? 1 : -1;
|
|   /* Detect bugs in glibc 2.4 and Solaris 10 stdint.h, among others.  */
|   int check_UINT8_C:
|         (-1 < UINT8_C (0)) == (-1 < (uint_least8_t) 0) ? 1 : -1;
|   int check_UINT16_C:
|         (-1 < UINT16_C (0)) == (-1 < (uint_least16_t) 0) ? 1 : -1;
|
|   /* Detect bugs in OpenBSD 3.9 stdint.h.  */
| #ifdef UINT8_MAX
|   int check_uint8: (uint8_t) -1 == UINT8_MAX ? 1 : -1;
| #endif
| #ifdef UINT16_MAX
|   int check_uint16: (uint16_t) -1 == UINT16_MAX ? 1 : -1;
| #endif
| #ifdef UINT32_MAX
|   int check_uint32: (uint32_t) -1 == UINT32_MAX ? 1 : -1;
| #endif
| #ifdef UINT64_MAX
|   int check_uint64: (uint64_t) -1 == UINT64_MAX ? 1 : -1;
| #endif
|   int check_uint_least8: (uint_least8_t) -1 == UINT_LEAST8_MAX ? 1 : -1;
|   int check_uint_least16: (uint_least16_t) -1 == UINT_LEAST16_MAX ? 1 : -1;
|   int check_uint_least32: (uint_least32_t) -1 == UINT_LEAST32_MAX ? 1 : -1;
|   int check_uint_least64: (uint_least64_t) -1 == UINT_LEAST64_MAX ? 1 : -1;
|   int check_uint_fast8: (uint_fast8_t) -1 == UINT_FAST8_MAX ? 1 : -1;
|   int check_uint_fast16: (uint_fast16_t) -1 == UINT_FAST16_MAX ? 1 : -1;
|   int check_uint_fast32: (uint_fast32_t) -1 == UINT_FAST32_MAX ? 1 : -1;
|   int check_uint_fast64: (uint_fast64_t) -1 == UINT_FAST64_MAX ? 1 : -1;
|   int check_uintptr: (uintptr_t) -1 == UINTPTR_MAX ? 1 : -1;
|   int check_uintmax: (uintmax_t) -1 == UINTMAX_MAX ? 1 : -1;
|   int check_size: (size_t) -1 == SIZE_MAX ? 1 : -1;
| };
|
| int
| main ()
| {
|
|   ;
|   return 0;
| }
configure:9079: result: no
~~~


$ grep -rn gl_cv_header_working_stdint_h
config.cache:628:gl_cv_header_working_stdint_h=${gl_cv_header_working_stdint_h=no}
config.log:39493:gl_cv_header_working_stdint_h=no

But, I don't get a replacement:

$ find . -name stdint.h
$

Any hints on where I should be looking next?

Thanks,
Pedro Alves



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-02 10:36   ` Pedro Alves
@ 2015-11-02 11:03     ` Pedro Alves
  2015-11-02 15:36       ` [PATCH] " Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-02 11:03 UTC (permalink / raw
  To: Paul Eggert, bug-gnulib

On 11/02/2015 10:36 AM, Pedro Alves wrote:

> $ grep -rn gl_cv_header_working_stdint_h
> config.cache:628:gl_cv_header_working_stdint_h=${gl_cv_header_working_stdint_h=no}
> config.log:39493:gl_cv_header_working_stdint_h=no
> 
> But, I don't get a replacement:
> 
> $ find . -name stdint.h
> $
> 
> Any hints on where I should be looking next?

Hmm, I looked for how headers end up or not generated, and found out how that
makes it to the Makefile, and noticed that the stdint.h generation in my Makefile
was commented out.  Turns out my Makefile was stale, even after having done (I
believe) several config.status --recheck last night.  Today I
re-ran "config.status", and lo, I get a replacement stdint.h.

Sorry for the false alarm.

Thanks,
Pedro Alves



^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH] Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-02 11:03     ` Pedro Alves
@ 2015-11-02 15:36       ` Pedro Alves
  2015-11-03  2:32         ` Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-02 15:36 UTC (permalink / raw
  To: Paul Eggert, bug-gnulib

On 11/02/2015 11:03 AM, Pedro Alves wrote:
> On 11/02/2015 10:36 AM, Pedro Alves wrote:
> 
>> $ grep -rn gl_cv_header_working_stdint_h
>> config.cache:628:gl_cv_header_working_stdint_h=${gl_cv_header_working_stdint_h=no}
>> config.log:39493:gl_cv_header_working_stdint_h=no
>>
>> But, I don't get a replacement:
>>
>> $ find . -name stdint.h
>> $
>>
>> Any hints on where I should be looking next?
> 
> Hmm, I looked for how headers end up or not generated, and found out how that
> makes it to the Makefile, and noticed that the stdint.h generation in my Makefile
> was commented out.  Turns out my Makefile was stale, even after having done (I
> believe) several config.status --recheck last night.  Today I
> re-ran "config.status", and lo, I get a replacement stdint.h.
> 
> Sorry for the false alarm.

Alright, and now with the stdint.h replacement, I tripped on
a real problem.  E.g.:

../../src/gdb/dcache.c: In function 'dcache_block* dcache_alloc(DCACHE*, CORE_ADDR)':
../../src/gdb/dcache.c:387:27: error: cast from 'dcache_block*' to 'splay_tree_value {aka long unsigned int}' loses precision [-fpermissive]
        (splay_tree_value) db);
                           ^

splay_tree_value is a typedef for uintptr_t.  And gnulib's stdint.h
replacement typedef that to "unsigned long":

~~~
/* 7.18.1.4. Integer types capable of holding object pointers */

#undef intptr_t
#undef uintptr_t
typedef long int gl_intptr_t;
typedef unsigned long int gl_uintptr_t;
#define intptr_t gl_intptr_t
#define uintptr_t gl_uintptr_t
~~~

which is not appropriate for mingw/64-bit, which is LLP64.

Given that mingw's stdint.h is good enough if one defines
__STDC_CONSTANT_MACROS / __STDC_LIMIT_MACROS, seems like the best fix
would be to make it so that the only thing the gnulib replacement
does is define __STDC_..._MACROS and include_next mingw's stdint.h,
nothing else.  See patch below.  What do you think?

>From 1fb3ed739c8e03e2f1459b033b4fe57cfd562dd8 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 2 Nov 2015 14:52:18 +0000
Subject: [PATCH] stdint: detect good enough pre-C++11 stdint.h in C++ mode

When gnulib is configured in C++ mode for a system with a working C99
implementation of stdint.h that predates C++11, gnulib ends up
substituing stdint.h anyway.  This works on most targets, but on e.g.,
64-bit MinGW, it doesn't, as gnulib's substitute assumes LP64, while
MinGW is LLP64:

~~~
/* 7.18.1.4. Integer types capable of holding object pointers */

#undef intptr_t
#undef uintptr_t
typedef long int gl_intptr_t;
typedef unsigned long int gl_uintptr_t;
#define intptr_t gl_intptr_t
#define uintptr_t gl_uintptr_t
~~~

Instead of trying to detect the right types, detect
good-enough-pre-C++11 stdint.h and in such case make the substitute
stdint.h just wrap the system's stdint.h with
__STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.

	* lib/stdint.in.h: Skip defining replacement header contents if
	@HAVE_PRE_CXX11_STDINT_H@, indicating the system's stdint.h is
	good enough and just needs __STDC_CONSTANT_MACROS /
	__STDC_LIMIT_MACROS defined in C++.
	* m4/stdint.m4 (gl_STDINT_H): Always define __STDC_CONSTANT_MACROS
	/ __STDC_LIMIT_MACROS while checking whether the system stdint.h
	is good.  If it is good, check whether it works without those
	macros defined.  Then if it doesn't work, generate a replacement
	header that just defines those macros and includes the system
	stdint.h.
	* modules/stdint (Makefile.am): Substitute
	@HAVE_PRE_CXX11_STDINT_H@.
---
 lib/stdint.in.h |  4 +++-
 m4/stdint.m4    | 33 +++++++++++++++++++++++++++++++--
 modules/stdint  |  1 +
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/lib/stdint.in.h b/lib/stdint.in.h
index f46bbf3..fecb5e1 100644
--- a/lib/stdint.in.h
+++ b/lib/stdint.in.h
@@ -76,7 +76,9 @@
 # @INCLUDE_NEXT@ @NEXT_STDINT_H@
 #endif
 
-#if ! defined _@GUARD_PREFIX@_STDINT_H && ! defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H
+#if (! defined _@GUARD_PREFIX@_STDINT_H			\
+     && ! (defined _GL_JUST_INCLUDE_SYSTEM_STDINT_H	\
+	   || @HAVE_PRE_CXX11_STDINT_H@))
 #define _@GUARD_PREFIX@_STDINT_H
 
 /* <sys/types.h> defines some of the stdint.h types as well, on glibc,
diff --git a/m4/stdint.m4 b/m4/stdint.m4
index 4011a49..4b98596 100644
--- a/m4/stdint.m4
+++ b/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 43
+# stdint.m4 serial 44
 dnl Copyright (C) 2001-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -70,6 +70,8 @@ AC_DEFUN_ONCE([gl_STDINT_H],
        AC_COMPILE_IFELSE([
          AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>.  */
 #if !(defined WCHAR_MIN && defined WCHAR_MAX)
@@ -218,6 +220,8 @@ struct s {
           AC_RUN_IFELSE([
             AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 ]
 gl_STDINT_INCLUDES
@@ -279,7 +283,30 @@ static const char *macro_values[] =
       ])
   fi
   if test "$gl_cv_header_working_stdint_h" = yes; then
-    STDINT_H=
+    dnl Now see whether the system <stdint.h> works without
+    dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
+    AC_CACHE_CHECK([whether stdint.h predates C++11],
+      [gl_cv_header_stdint_predates_cxx11_h],
+      [gl_cv_header_stdint_predates_cxx11_h=yes
+       AC_COMPILE_IFELSE([
+	 AC_LANG_PROGRAM([[
+#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#include <stdint.h>
+]
+gl_STDINT_INCLUDES
+[
+intmax_t im = INTMAX_MAX;
+int32_t i32 = INT32_C (0x7fffffff);
+         ]])],
+         [gl_cv_header_stdint_predates_cxx11_h=no])])
+
+    if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then
+      HAVE_PRE_CXX11_STDINT_H=1
+      STDINT_H=stdint.h
+    else
+      HAVE_PRE_CXX11_STDINT_H=0
+      STDINT_H=
+    fi
   else
     dnl Check for <sys/inttypes.h>, and for
     dnl <sys/bitypes.h> (used in Linux libc4 >= 4.6.7 and libc5).
@@ -299,7 +326,9 @@ static const char *macro_values[] =
 
     gl_STDINT_TYPE_PROPERTIES
     STDINT_H=stdint.h
+    HAVE_PRE_CXX11_STDINT_H=0
   fi
+  AC_SUBST([HAVE_PRE_CXX11_STDINT_H])
   AC_SUBST([STDINT_H])
   AM_CONDITIONAL([GL_GENERATE_STDINT_H], [test -n "$STDINT_H"])
 ])
diff --git a/modules/stdint b/modules/stdint
index 62a5797..094f959 100644
--- a/modules/stdint
+++ b/modules/stdint
@@ -55,6 +55,7 @@ stdint.h: stdint.in.h $(top_builddir)/config.status
 	      -e 's/@''BITSIZEOF_WINT_T''@/$(BITSIZEOF_WINT_T)/g' \
 	      -e 's/@''HAVE_SIGNED_WINT_T''@/$(HAVE_SIGNED_WINT_T)/g' \
 	      -e 's/@''WINT_T_SUFFIX''@/$(WINT_T_SUFFIX)/g' \
+	      -e 's/@''HAVE_PRE_CXX11_STDINT_H''@/$(HAVE_PRE_CXX11_STDINT_H)/g' \
 	      < $(srcdir)/stdint.in.h; \
 	} > $@-t && \
 	mv $@-t $@
-- 
1.9.3




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-02 15:36       ` [PATCH] " Pedro Alves
@ 2015-11-03  2:32         ` Paul Eggert
  2015-11-03 14:45           ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Paul Eggert @ 2015-11-03  2:32 UTC (permalink / raw
  To: Pedro Alves, bug-gnulib

Pedro Alves wrote:
> Instead of trying to detect the right types, detect
> good-enough-pre-C++11 stdint.h and in such case make the substitute
> stdint.h just wrap the system's stdint.h with
> __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.

Instead, how about just adding the necessary #defines for 
__STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS to config.h if they are needed to fix 
the bug?  Then we can leave stdint.h alone (perhaps not even build stdint.h at all).


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-03  2:32         ` Paul Eggert
@ 2015-11-03 14:45           ` Pedro Alves
  2015-11-03 14:55             ` Pedro Alves
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-03 14:45 UTC (permalink / raw
  To: Paul Eggert, bug-gnulib

On 11/03/2015 02:32 AM, Paul Eggert wrote:
> Pedro Alves wrote:
>> Instead of trying to detect the right types, detect
>> good-enough-pre-C++11 stdint.h and in such case make the substitute
>> stdint.h just wrap the system's stdint.h with
>> __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
> 
> Instead, how about just adding the necessary #defines for 
> __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS to config.h if they are needed to fix 
> the bug?  Then we can leave stdint.h alone (perhaps not even build stdint.h at all).

The downside could be that config.h's #defines are unconditional, instead of guarded
against multiple definition with #ifndef, as they are currently in the replacement
stdint.h.  I was worried (a bit) that that may break packages that have build
systems that pass something like -D__STDC_CONSTANT_MACROS on the command line.

But because -DFOO defines FOO as 1, this doesn't error out:

  echo "#define FOO 1" | g++ -Werror -DFOO -E -

Given that config.h defines symbols to 1, I guess that concern is moot.

(But that speaks nothing of other compilers gnulib supports, naturally.)

I'll update the patch in that direction.

Thanks,
Pedro Alves



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH] Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-03 14:45           ` Pedro Alves
@ 2015-11-03 14:55             ` Pedro Alves
  2016-04-04  6:06               ` Paul Eggert
  0 siblings, 1 reply; 9+ messages in thread
From: Pedro Alves @ 2015-11-03 14:55 UTC (permalink / raw
  To: Paul Eggert; +Cc: bug-gnulib

On 11/03/2015 02:45 PM, Pedro Alves wrote:
> On 11/03/2015 02:32 AM, Paul Eggert wrote:
>> Pedro Alves wrote:
>>> Instead of trying to detect the right types, detect
>>> good-enough-pre-C++11 stdint.h and in such case make the substitute
>>> stdint.h just wrap the system's stdint.h with
>>> __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
>>

>> Instead, how about just adding the necessary #defines for 
>> __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS to config.h if they are needed to fix 
>> the bug?  Then we can leave stdint.h alone (perhaps not even build stdint.h at all).

> I'll update the patch in that direction.

Here's the updated patch.

-------------------
>From e6f4dc6da7d2ef60a5647e4d1bc673572011a463 Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Mon, 2 Nov 2015 14:52:18 +0000
Subject: [PATCH] stdint: detect good enough pre-C++11 stdint.h in C++ mode

When gnulib is configured in C++ mode for a system with a working C99
implementation of stdint.h that predates C++11, gnulib ends up
substituing stdint.h anyway.  This works on most targets, but on e.g.,
64-bit MinGW, it doesn't, as gnulib's substitute assumes LP64, while
MinGW is LLP64:

~~~
/* 7.18.1.4. Integer types capable of holding object pointers */

#undef intptr_t
#undef uintptr_t
typedef long int gl_intptr_t;
typedef unsigned long int gl_uintptr_t;
#define intptr_t gl_intptr_t
#define uintptr_t gl_uintptr_t
~~~

Instead of trying to detect the right types, detect
good-enough-pre-C++11 stdint.h and in such case define
__STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS in config.h.

	* m4/stdint.m4 (gl_STDINT_H): Always define __STDC_CONSTANT_MACROS
	/ __STDC_LIMIT_MACROS while checking whether the system stdint.h
	conforms to C99.  If it does, check whether it hides symbols
	behind the __STDC_{CONSTANT|LIMIT}_MACROS macros.  Then if it
	does, define those macros in config.h.
---
 m4/stdint.m4 | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/m4/stdint.m4 b/m4/stdint.m4
index 4011a49..4244c05 100644
--- a/m4/stdint.m4
+++ b/m4/stdint.m4
@@ -1,4 +1,4 @@
-# stdint.m4 serial 43
+# stdint.m4 serial 44
 dnl Copyright (C) 2001-2015 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -70,6 +70,8 @@ AC_DEFUN_ONCE([gl_STDINT_H],
        AC_COMPILE_IFELSE([
          AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 /* Dragonfly defines WCHAR_MIN, WCHAR_MAX only in <wchar.h>.  */
 #if !(defined WCHAR_MIN && defined WCHAR_MAX)
@@ -218,6 +220,8 @@ struct s {
           AC_RUN_IFELSE([
             AC_LANG_PROGRAM([[
 #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#define __STDC_CONSTANT_MACROS 1
+#define __STDC_LIMIT_MACROS 1
 #include <stdint.h>
 ]
 gl_STDINT_INCLUDES
@@ -279,6 +283,29 @@ static const char *macro_values[] =
       ])
   fi
   if test "$gl_cv_header_working_stdint_h" = yes; then
+    dnl Now see whether the system <stdint.h> works without
+    dnl __STDC_CONSTANT_MACROS/__STDC_LIMIT_MACROS defined.
+    AC_CACHE_CHECK([whether stdint.h predates C++11],
+      [gl_cv_header_stdint_predates_cxx11_h],
+      [gl_cv_header_stdint_predates_cxx11_h=yes
+       AC_COMPILE_IFELSE([
+	 AC_LANG_PROGRAM([[
+#define _GL_JUST_INCLUDE_SYSTEM_STDINT_H 1 /* work if build isn't clean */
+#include <stdint.h>
+]
+gl_STDINT_INCLUDES
+[
+intmax_t im = INTMAX_MAX;
+int32_t i32 = INT32_C (0x7fffffff);
+         ]])],
+         [gl_cv_header_stdint_predates_cxx11_h=no])])
+
+    if test "$gl_cv_header_stdint_predates_cxx11_h" = yes; then
+      AC_DEFINE([__STDC_CONSTANT_MACROS], [1],
+                [Define to 1 if the system <stdint.h> predates C++11.])
+      AC_DEFINE([__STDC_LIMIT_MACROS], [1],
+                [Define to 1 if the system <stdint.h> predates C++11.])
+    fi
     STDINT_H=
   else
     dnl Check for <sys/inttypes.h>, and for
-- 
1.9.3




^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH] Re: stdint.h, C++ and __STDC_LIMIT_MACROS
  2015-11-03 14:55             ` Pedro Alves
@ 2016-04-04  6:06               ` Paul Eggert
  0 siblings, 0 replies; 9+ messages in thread
From: Paul Eggert @ 2016-04-04  6:06 UTC (permalink / raw
  To: Pedro Alves; +Cc: bug-gnulib

Pedro Alves wrote:
> Here's the updated patch.

Thanks, I installed that. Sorry about the long delay; my inbox was overflowing.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-04-04  6:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-11-01 17:37 stdint.h, C++ and __STDC_LIMIT_MACROS Pedro Alves
2015-11-02  1:36 ` Paul Eggert
2015-11-02 10:36   ` Pedro Alves
2015-11-02 11:03     ` Pedro Alves
2015-11-02 15:36       ` [PATCH] " Pedro Alves
2015-11-03  2:32         ` Paul Eggert
2015-11-03 14:45           ` Pedro Alves
2015-11-03 14:55             ` Pedro Alves
2016-04-04  6:06               ` Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).