From 45e1ad619b0db9bad22f2ffaeae2e4e5cba230aa Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 28 Oct 2022 13:38:11 -0700 Subject: [PROPOSED] Fix usage of __has_include MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem with GCC 4.8.3 reported by Igor Ivanov in: https://mm.icann.org/pipermail/tz/2022-October/032129.html * private.h (true, false, bool) [__STDC_VERSION__ < 202311]: Define early so that we needn’t worry about using these macros before they’re defined. (HAS_INCLUDE): Remove. This macro was misguided, as C23 says the behavior is undefined if a macro body expands to __has_include(...). All uses of HAS_INCLUDE replaced by direct invocations of __has_include; or if the old code used __STDC_VERSION__ just go back to that as it still works for __STDC_VERSION__ == 202311. This patch also works around the problem reported for GCC 4.8.3. --- private.h | 78 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 46 insertions(+), 32 deletions(-) diff --git a/private.h b/private.h index deff90ea..18f6a055 100644 --- a/private.h +++ b/private.h @@ -17,6 +17,15 @@ ** Thank you! */ +/* Define true, false and bool if they don't work out of the box. */ +#if __STDC_VERSION__ < 199901 +# define true 1 +# define false 0 +# define bool int +#elif __STDC_VERSION__ < 202311 +# include +#endif + /* ** zdump has been made independent of the rest of the time ** conversion package to increase confidence in the verification it provides. @@ -30,14 +39,6 @@ /* This string was in the Factory zone through version 2016f. */ #define GRANDPARENTED "Local time zone must be set--see zic manual page" -/* True if "#include INCLUDE" includes something, false otherwise. - Yield DEFAULT on pre-C23 platforms that lack __has_include. */ -#ifdef __has_include -# define HAS_INCLUDE(include, default) __has_include(include) -#else -# define HAS_INCLUDE(include, default) (default) -#endif - /* ** Defaults for preprocessor symbols. ** You can override these in your C compiler options, e.g. '-DHAVE_GETTEXT=1'. @@ -62,13 +63,24 @@ # define HAVE_GENERIC (201112 <= __STDC_VERSION__) #endif +#if !defined HAVE_GETRANDOM && defined __has_include +# if __has_include() +# define HAVE_GETRANDOM true +# else +# define HAVE_GETRANDOM false +# endif +#endif #ifndef HAVE_GETRANDOM -# define HAVE_GETRANDOM HAS_INCLUDE(, \ - (2 < __GLIBC__ + (25 <= __GLIBC_MINOR__))) +# define HAVE_GETRANDOM (2 < __GLIBC__ + (25 <= __GLIBC_MINOR__)) #endif +#if !defined HAVE_GETTEXT && defined __has_include +# if __has_include() +# define HAVE_GETTEXT true +# endif +#endif #ifndef HAVE_GETTEXT -# define HAVE_GETTEXT HAS_INCLUDE(, false) +# define HAVE_GETTEXT false #endif #ifndef HAVE_INCOMPATIBLE_CTIME_R @@ -103,16 +115,22 @@ # define HAVE_SYMLINK 1 #endif /* !defined HAVE_SYMLINK */ +#if !defined HAVE_SYS_STAT_H && defined __has_include +# if !__has_include() +# define HAVE_SYS_STAT_H false +# endif +#endif #ifndef HAVE_SYS_STAT_H -# define HAVE_SYS_STAT_H HAS_INCLUDE(, true) +# define HAVE_SYS_STAT_H true #endif -#ifndef HAVE_UNISTD_H -# define HAVE_UNISTD_H HAS_INCLUDE(, true) +#if !defined HAVE_UNISTD_H && defined __has_include +# if !__has_include() +# define HAVE_UNISTD_H false +# endif #endif - -#ifndef HAVE_UTMPX_H -# define HAVE_UTMPX_H HAS_INCLUDE(, true) +#ifndef HAVE_UNISTD_H +# define HAVE_UNISTD_H true #endif #ifndef NETBSD_INSPIRED @@ -249,18 +267,22 @@ ** previously-included files. glibc 2.1 and Solaris 10 and later have ** stdint.h, even with pre-C99 compilers. */ -#ifndef HAVE_STDINT_H -# define HAVE_STDINT_H HAS_INCLUDE(, \ - (199901 <= __STDC_VERSION__ \ - || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ - || __CYGWIN__ || INTMAX_MAX)) +#if !defined HAVE_STDINT_H && defined __has_include +# define HAVE_STDINT_H true /* C23 __has_include implies C99 stdint.h. */ #endif +#ifndef HAVE_STDINT_H +# define HAVE_STDINT_H \ + (199901 <= __STDC_VERSION__ \ + || 2 < __GLIBC__ + (1 <= __GLIBC_MINOR__) \ + || __CYGWIN__ || INTMAX_MAX) +#endif /* !defined HAVE_STDINT_H */ + #if HAVE_STDINT_H # include -#endif +#endif /* !HAVE_STDINT_H */ #ifndef HAVE_INTTYPES_H -# define HAVE_INTTYPES_H HAS_INCLUDE(, HAVE_STDINT_H) +# define HAVE_INTTYPES_H HAVE_STDINT_H #endif #if HAVE_INTTYPES_H # include @@ -630,14 +652,6 @@ time_t time2posix_z(timezone_t, time_t) ATTRIBUTE_PURE; ** Finally, some convenience items. */ -#if __STDC_VERSION__ < 199901 -# define true 1 -# define false 0 -# define bool int -#elif __STDC_VERSION__ < 202311 -# include -#endif - #define TYPE_BIT(type) (sizeof(type) * CHAR_BIT) #define TYPE_SIGNED(type) (((type) -1) < 0) #define TWOS_COMPLEMENT(t) ((t) ~ (t) 0 < 0) -- 2.37.2