[cfe-dev] Keyword warnings in libc++'s type_traits and other headers
Howard Hinnant
howard.hinnant at gmail.com
Mon Dec 23 13:16:50 PST 2013
On Dec 22, 2013, at 4:27 PM, Dimitry Andric <dimitry at andric.com> wrote:
> Hi,
>
> I ran into a situation where a C++ program was compiled with -Wsystem-headers. When I did this with clang 3.4 or trunk, I got the following keyword warnings:
>
> In file included from include/algorithm:624:
> include/type_traits:288:29: warning: keyword '__is_void' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_void : public false_type {};
> ^
> include/type_traits:309:29: warning: keyword '__is_integral' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_integral : public false_type {};
> ^
> include/type_traits:333:29: warning: keyword '__is_floating_point' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_floating_point : public false_type {};
> ^
> include/type_traits:352:29: warning: keyword '__is_pointer' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_pointer : public false_type {};
> ^
> include/type_traits:432:8: warning: keyword '__is_function' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> struct __is_function
> ^
> include/type_traits:442:40: warning: keyword '__is_member_function_pointer' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_member_function_pointer : public false_type {};
> ^
> include/type_traits:450:40: warning: keyword '__is_member_pointer' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> template <class _Tp> struct __is_member_pointer : public false_type {};
> ^
> include/type_traits:653:8: warning: keyword '__is_signed' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> struct __is_signed : public ___is_signed<_Tp> {};
> ^
> include/type_traits:668:8: warning: keyword '__is_unsigned' will be made available as an identifier for the remainder of the translation unit [-Wkeyword-compat]
> struct __is_unsigned : public ___is_unsigned<_Tp> {};
> ^
> 9 warnings generated.
>
> This seems to have been introduced with r196212 in clang by Alp Toker, but it is unfortunate the warning hits libc++. :-) The cause is a bunch of Embarcadero keywords defined in clang's lib/Parse/ParseExpr.cpp, which are exactly the same as these libc++-internal identifers.
>
> Is the attached patch acceptable as a workaround?
Two further questions:
1. Do these keywords come with __has_feature tests (like __is_class does)? If not, they should.
2. If they do come with __has_feature tests, how about libc++ doing the same thing it does for is_class et al.?
#if !__has_feature(is_void)
template <class _Tp> struct __is_void : public false_type {};
template <> struct __is_void<void> : public true_type {};
#endif // !__has_feature(is_void)
template <class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_void
: public __is_void<typename remove_cv<_Tp>::type> {};
That way we don't need major surgery. We avoid the conflict if it exists. And we take advantage of the compiler intrinsic if it exists.
Is there a conflict that can not be handled in this way?
Howard
More information about the cfe-dev
mailing list