This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by chatur01 on Apr 21 2015, 9:47 AM.
This revision needs review, but there are no reviewers specified.

Details

Reviewers
None
Summary

Extends the hackish recovery in r130399 to deal with the case of bool being hidden behind a typedef.

Fixes PR9804

Diff Detail

Repository
rL LLVM

Event Timeline

chatur01 retitled this revision from to [PATCH] PR9804 - __is_signed conflicts with libstdc++.
chatur01 updated this object.
chatur01 edited the test plan for this revision. (Show Details)
chatur01 set the repository for this revision to rL LLVM.
chatur01 added a subscriber: Unknown Object (MLST).
rsmith added a subscriber: rsmith.Apr 21 2015, 11:23 AM

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

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. :)