From 31f9476c9ec08b0a21a71fce807fc72fef0c6441 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 9 Aug 2020 15:01:23 +0200 Subject: [PATCH] Use __typeof__ with clang. * m4/stdint.m4 (gl_STDINT_H): Check for SIZE_MAX also on "clang -std=gnu99". * lib/intprops.h (_GL_HAVE___TYPEOF__): Define to 1 also on clang. * tests/test-stdint.c (verify_same_types): Enable the check also on clang. --- ChangeLog | 9 +++++++++ lib/intprops.h | 1 + m4/stdint.m4 | 4 ++-- tests/test-stdint.c | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1c48b2153..77fb963613 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2020-08-09 Bruno Haible + + Use __typeof__ with clang. + * m4/stdint.m4 (gl_STDINT_H): Check for SIZE_MAX also on + "clang -std=gnu99". + * lib/intprops.h (_GL_HAVE___TYPEOF__): Define to 1 also on clang. + * tests/test-stdint.c (verify_same_types): Enable the check also on + clang. + 2020-08-09 Bruno Haible Add ability to emit user-defined warnings and errors with clang. diff --git a/lib/intprops.h b/lib/intprops.h index c0bfecd908..2ab1b6ff6a 100644 --- a/lib/intprops.h +++ b/lib/intprops.h @@ -86,6 +86,7 @@ /* Does the __typeof__ keyword work? This could be done by 'configure', but for now it's easier to do it by hand. */ #if (2 <= __GNUC__ \ + || (4 <= __clang_major__) \ || (1210 <= __IBMC__ && defined __IBM__TYPEOF__) \ || (0x5110 <= __SUNPRO_C && !__STDC__)) # define _GL_HAVE___TYPEOF__ 1 diff --git a/m4/stdint.m4 b/m4/stdint.m4 index 29ad826d8e..e0fa8a51fb 100644 --- a/m4/stdint.m4 +++ b/m4/stdint.m4 @@ -1,4 +1,4 @@ -# stdint.m4 serial 54 +# stdint.m4 serial 55 dnl Copyright (C) 2001-2020 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -152,7 +152,7 @@ uintmax_t j = UINTMAX_MAX; /* Check that SIZE_MAX has the correct type, if possible. */ #if 201112 <= __STDC_VERSION__ int k = _Generic (SIZE_MAX, size_t: 0); -#elif (2 <= __GNUC__ || defined __IBM__TYPEOF__ \ +#elif (2 <= __GNUC__ || 4 <= __clang_major__ || defined __IBM__TYPEOF__ \ || (0x5110 <= __SUNPRO_C && !__STDC__)) extern size_t k; extern __typeof__ (SIZE_MAX) k; diff --git a/tests/test-stdint.c b/tests/test-stdint.c index 6da84b274f..5e4f30cde1 100644 --- a/tests/test-stdint.c +++ b/tests/test-stdint.c @@ -26,7 +26,7 @@ #include "verify.h" #include "intprops.h" -#if __GNUC__ >= 2 && DO_PEDANTIC +#if ((__GNUC__ >= 2) || (__clang_major__ >= 4)) && DO_PEDANTIC # define verify_same_types(expr1,expr2) \ extern void _verify_func(__LINE__) (__typeof__ (expr1) *); \ extern void _verify_func(__LINE__) (__typeof__ (expr2) *); -- 2.39.5