[tz] [PROPOSED 2/5] Pacify gcc -std=c89 -pedantic with new attributes

Philip Newton philip.newton at gmail.com
Mon Nov 28 13:40:00 UTC 2022


"have has" is a bit ugly....

Cheers,
Philip

On Mon, 21 Nov 2022 at 19:37, Paul Eggert via tz <tz at iana.org> wrote:
>
> * private.h (__STDC_VERSION__): Default to 0.
> (ATTRIBUTE_MAYBE_UNUSED, ATTRIBUTE_NORETURN): Avoid diagnostic
> about use of [[...]] with 'gcc -std=c89 -pedantic'.
> ---
>  private.h | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/private.h b/private.h
> index fa46094b..b9803427 100644
> --- a/private.h
> +++ b/private.h
> @@ -17,6 +17,10 @@
>  ** Thank you!
>  */
>
> +#ifndef __STDC_VERSION__
> +# define __STDC_VERSION__ 0
> +#endif
> +
>  /* Define true, false and bool if they don't work out of the box.  */
>  #if __STDC_VERSION__ < 199901
>  # define true 1
> @@ -433,7 +437,14 @@ typedef unsigned long uintmax_t;
>  # define ATTRIBUTE_FORMAT(spec) /* empty */
>  #endif
>
> -#ifdef __has_c_attribute
> +#if (defined __has_c_attribute \
> +     && (202311 <= __STDC_VERSION__ || !defined __STRICT_ANSI__))
> +# define HAVE_HAS_C_ATTRIBUTE true
> +#else
> +# define HAVE_HAS_C_ATTRIBUTE false
> +#endif
> +
> +#if HAVE_HAS_C_ATTRIBUTE
>  # if __has_c_attribute(maybe_unused)
>  #  define ATTRIBUTE_MAYBE_UNUSED [[maybe_unused]]
>  # endif
> @@ -446,7 +457,7 @@ typedef unsigned long uintmax_t;
>  # endif
>  #endif
>
> -#ifdef __has_c_attribute
> +#if HAVE_HAS_C_ATTRIBUTE
>  # if __has_c_attribute(noreturn)
>  #  define ATTRIBUTE_NORETURN [[noreturn]]
>  # endif
> --
> 2.37.2
>


-- 
Philip Newton <philip.newton at gmail.com>


More information about the tz mailing list