This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] float128: Extend __MATH_TG for float128 support
On Mon, 15 May 2017 21:49:05 +0000
Joseph Myers <joseph@codesourcery.com> wrote:
> On Mon, 15 May 2017, Gabriel F. T. Gomes wrote:
>
> > +#elif __HAVE_DISTINCT_FLOAT128
> > +# if __USE_ISOC11
> > +# define __MATH_TG(TG_ARG, FUNC, ARGS) \
> > + _Generic ((TG_ARG), \
> > + float: FUNC ## f ARGS, \
> > + default: FUNC ARGS, \
> > + long double: FUNC ## l ARGS, \
> > + _Float128: FUNC ## f128 ARGS)
>
> __USE_ISOC11 is about whether to declare library functions etc. from C11;
> it's nothing to do with whether there's compiler support for C11.
> Something like
>
> __GNUC_PREREQ (4, 9) || (!defined __GNUC__ && defined __STDC_VERSION__ && __STDC_VERSION__ >= 201112L)
>
> would be more appropriate (or use that to define a macro in sys/cdefs.h
> for whether _Generic is available).
>
Should I also add a clang-specific test, since Clang also defines __GNUC__?
Something like the following in sys/cdefs.h:
/* Support for generic selection (ISO C11) is available in GCC since
version 4.9. Previous versions do not provide generic selection,
even though they might set __STDC_VERSION__ to 201112L, when in
-std=c11 mode. Thus, we must check for !defined __GNUC__ when
testing __STDC_VERSION__ for generic selection support.
On the other hand, Clang also defines __GNUC__, so a clang-specific
check is required to enable the use of generic selection. */
#if __GNUC_PREREQ (4, 9) \
|| __glibc_clang_has_extension (c_generic_selections) \
|| (!defined __GNUC__ && defined __STDC_VERSION__ \
&& __STDC_VERSION__ >= 201112L)
# define __HAVE_GENERIC_SELECTION 1
#else
# define __HAVE_GENERIC_SELECTION 0
#endif
And is __HAVE_GENERIC_SELECTION a good name for a macro in sys/cdefs.h?
Reference for the clang check:
http://clang.llvm.org/docs/LanguageExtensions.html#c11-generic-selections