Re: [PATCH] lib: have two definitions of NOTMUCH_DEPRECATED macro

Subject: Re: [PATCH] lib: have two definitions of NOTMUCH_DEPRECATED macro

Date: Tue, 29 Dec 2015 13:52:20 +0200

To: Tomi Ollila, notmuch@notmuchmail.org

Cc: tomi.ollila@iki.fi

From: Jani Nikula


On Tue, 11 Aug 2015, Tomi Ollila <tomi.ollila@iki.fi> wrote:
> Some compilers (older than gcc 4.5 and clang 2.9) do support
> __attribute__ ((deprecated)) but not
> __attribute__ ((deprecated("message"))).
>
> Check (clang) and know (gcc) which versions support which variants
> and make two definitions of define NOTMUCH_DEPRECATED macro;
> one with and and one without the ("message") part.
>
> __has_extension() replacement was modeled after __has_attribute()
> definition in compat/function-attributes.h. Thanks Justus.
> ---
>  lib/notmuch.h | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/lib/notmuch.h b/lib/notmuch.h
> index b1f5bfa..3f4621b 100644
> --- a/lib/notmuch.h
> +++ b/lib/notmuch.h
> @@ -59,8 +59,22 @@ NOTMUCH_BEGIN_DECLS
>  #define LIBNOTMUCH_MINOR_VERSION	3
>  #define LIBNOTMUCH_MICRO_VERSION	0
>  
> +/* clang provides this macro to test for support for language
> + * extensions. If it isn't defined, this provides a compatibility
> + * macro for other compilers.
> + */
> +#ifndef __has_extension
> +#define __has_extension(x) 0
> +#endif

This file is included by the users of the library, and thus this
definition leaks to our users. It might cause problems if the users have
different expectations for handling ifndef __has_extension. I don't
think we should define things outside of our namespace in notmuch.h.

BR,
Jani.

> +
> +#if __clang__ && __has_extension(attribute_deprecated_with_message) || \
> +    __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 5
>  #define NOTMUCH_DEPRECATED(major,minor) \
>      __attribute__ ((deprecated ("function deprecated as of libnotmuch " #major "." #minor)))
> +#else
> +#define NOTMUCH_DEPRECATED(major,minor) __attribute__ ((deprecated))
> +#endif
> +
>  #endif /* __DOXYGEN__ */
>  
>  /**
> -- 
> 2.4.3
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

Thread: