[PATCH] [PATCH] PR9804 - __is_signed conflicts with libstdc++

Charlie Turner charlie.turner at arm.com
Mon May 11 10:27:18 PDT 2015


In http://reviews.llvm.org/D9157#159383, @rsmith wrote:

> What is the motivation for this? Every version of libstdc++ I can find uses the keyword `bool` and not a typedef.


Sorry for the late reply Richard... I've also lost the previous thread I had with. I originally suggested the motivation was for cases like,

  typedef bool BOOL;
  
  class Foo {
      static const BOOL __is_signed;
    };
  
  #include <map>
  
  int main() {}

But as you pointed out, this is ill-formed. I found a smaller example, which I'm confident is well-formed yet rejected by Clang,

  typedef bool Bool;
  #define bool Bool
  
  #include <algorithm>
  
  int main(void) {} 

I see the following errors

  In file included from blentest.c:4:
  In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/algorithm:61:
  In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:63:
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/numeric_traits.h:63:25: error: expected member name or ';' after declaration specifiers
        static const bool __is_signed = __glibcxx_signed(_Value);
        ~~~~~~~~~~~~~~~~~ ^
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/numeric_traits.h:74:50: error: expected unqualified-id
      const bool __numeric_traits_integer<_Value>::__is_signed;
                                                   ^
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/numeric_traits.h:106:25: error: expected member name or ';' after declaration specifiers
        static const bool __is_signed = true;
        ~~~~~~~~~~~~~~~~~ ^
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/ext/numeric_traits.h:115:51: error: expected unqualified-id
      const bool __numeric_traits_floating<_Value>::__is_signed;
                                                    ^
  In file included from blentest.c:4:
  In file included from /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/algorithm:61:
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:941:49: error: expected unqualified-id
           && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
                                                         ^
  /usr/lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/bits/stl_algobase.h:946:45: error: non-type template argument of type 'Bool' (aka 'bool') is not an integral constant expression
        return std::__lexicographical_compare<__simple>::__lc(__first1, __last1,
                                              ^~~~~~~~
  6 errors generated.

The only restrictions I can see stated in the C++ standard (N4296, 2014-11-19) are in section 17.6.4.3.1, and they only cover that you're not allowed to `#define` or `#undef` names declared in a standard library header, or `override`, `final` and some other bits about attributes. `bool` is a fundamental type, so I think my example above should be accepted.

I think reopening PR9804 for this was incorrect, it looks quite similar, but perhaps I should open a new PR for this issue. Do you agree?

Thank you for your time. :)


REPOSITORY
  rL LLVM

http://reviews.llvm.org/D9157

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list