[PATCH] Use __is_same_as for std::is_same and std::is_same_v

Jonathan Wakely jwakely@redhat.com
Wed Oct 16 09:42:00 GMT 2019


On 12/10/19 18:15 +0200, Romain Geissler wrote:
>Le sam. 12 oct. 2019 à 17:44, Romain Geissler
><romain.geissler@gmail.com> a écrit :
>>
>> It looks like this creates the following error when I try to bootstrap
>> clang 9.0.0 using the latest gcc and libstdc++ from trunk. Note that
>> with g++, there is no problem, however it looks like clang++ has some
>> problem with the new header. I don't know if this is an issue on
>> libstdc++ side or clang++ side.
>
>__is_same_as is not implemented as a compiler builtin in clang++

Sigh, I guess that explains why we weren't using it already.

>unlike g++, thus the error on clang 9.0.0 side. It looks like current
>clang trunk doesn't define __is_same_as either. Until clang implements
>this support (if it ever will), usage of __is_same_as in libstdc++
>shall be conditional, only when __has_builtin(__is_same_as) is true
>(however that would require that gcc implements __has_builtin, as
>implemented here:
>https://gcc.gnu.org/ml/gcc-patches/2019-10/msg00062.html )

No, we don't need GCC to support __has_builtin, because we know GCC
supports __is_same_as so there's no need to check for it.

So something like this would work fine:

#if __GNUC__ >= 10
# define _GLIBCXX_HAVE__IS_SAME_AS
#elif defined(__has_builtin)
# if __has_builtin(__is_same_as)
#  define _GLIBCXX_HAVE__IS_SAME_AS
# endif
#endif





More information about the Libstdc++ mailing list