Commit dacd7bf0 authored by Laurent Stacul's avatar Laurent Stacul Committed by Facebook GitHub Bot

Fix compilation errors for C++20 (#1329)

Summary:
Compiling with gcc 10.0.1 and -std=gnu++2a, we have the following errors:
```
folly/FBString.h:1013:33: error: no type named 'reference' in 'class std::allocator<char>'
 1013 |   typedef typename A::reference reference;
      |                                 ^~~~~~~~~
folly/FBString.h:1014:39: error: no type named 'const_reference' in 'class std::allocator<char>'
 1014 |   typedef typename A::const_reference const_reference;
```
This is due to the fact many members in `std::allocator` have been remove in C++20: https://en.cppreference.com/w/cpp/memory/allocator

We also have this one due to the new way C++ resolves the comparison operators:
```
folly/dynamic-inl.h:854:20: error: ambiguous overload for 'operator!=' (operand types are 'folly::dynamic::const_item_iterator' and 'folly::dynamic::const_item_iterator')
  854 |   return find(key) != items().end() ? 1u : 0u;
      |          ~~~~~~~~~ ^~ ~~~~~~~~~~~~~
      |              |                   |
      |              |                   folly::dynamic::const_item_iterator
      |              folly::dynamic::const_item_iterator
In file included from folly/dynamic-inl.h:25,
                 from folly/dynamic.h:796,
                 from folly/dynamic.cpp:17:
folly/detail/Iterators.h:80:8: note: candidate: 'bool folly::detail::IteratorFacade<D, V, Tag>::operator==(const D&) const [with D = folly::dynamic::const_item_iterator; V = const std::pair<const folly::dynamic, folly::dynamic>; Tag = std::f
orward_iterator_tag]' (reversed)
   80 |   bool operator==(D const& rhs) const {
      |        ^~~~~~~~
folly/detail/Iterators.h:98:3: note: candidate: 'typename std::enable_if<std::is_convertible<D, D2>::value, bool>::type folly::detail::IteratorFacade<D, V, Tag>::operator==(const D2&) const [with D2 = folly::dynamic::const_item_iterator; D =
 folly::dynamic::const_item_iterator; V = const std::pair<const folly::dynamic, folly::dynamic>; Tag = std::forward_iterator_tag; typename std::enable_if<std::is_convertible<D, D2>::value, bool>::type = bool]' (reversed)
   98 |   operator==(D2 const& rhs) const {
      |   ^~~~~~~~
folly/detail/Iterators.h:84:8: note: candidate: 'bool folly::detail::IteratorFacade<D, V, Tag>::operator!=(const D&) const [with D = folly::dynamic::const_item_iterator; V = const std::pair<const folly::dynamic, folly::dynamic>; Tag = std::f
orward_iterator_tag]'
   84 |   bool operator!=(D const& rhs) const {
      |        ^~~~~~~~
folly/detail/Iterators.h:103:8: note: candidate: 'bool folly::detail::IteratorFacade<D, V, Tag>::operator!=(const D2&) const [with D2 = folly::dynamic::const_item_iterator; D = folly::dynamic::const_item_iterator; V = const std::pair<const f
olly::dynamic, folly::dynamic>; Tag = std::forward_iterator_tag]'
  103 |   bool operator!=(D2 const& rhs) const {
      |        ^~~~~~~~
```
Pull Request resolved: https://github.com/facebook/folly/pull/1329

Reviewed By: ot, igorsugak

Differential Revision: D20443631

Pulled By: yfeldblum

fbshipit-source-id: 03e8210a64a3eeaefb6f14afaddf45be882e3ba6
parent e1868ae2
...@@ -1007,13 +1007,13 @@ class basic_fbstring { ...@@ -1007,13 +1007,13 @@ class basic_fbstring {
typedef T traits_type; typedef T traits_type;
typedef typename traits_type::char_type value_type; typedef typename traits_type::char_type value_type;
typedef A allocator_type; typedef A allocator_type;
typedef typename A::size_type size_type; typedef typename std::allocator_traits<A>::size_type size_type;
typedef typename A::difference_type difference_type; typedef typename std::allocator_traits<A>::difference_type difference_type;
typedef typename A::reference reference; typedef typename std::allocator_traits<A>::value_type& reference;
typedef typename A::const_reference const_reference; typedef typename std::allocator_traits<A>::value_type const& const_reference;
typedef typename A::pointer pointer; typedef typename std::allocator_traits<A>::pointer pointer;
typedef typename A::const_pointer const_pointer; typedef typename std::allocator_traits<A>::const_pointer const_pointer;
typedef E* iterator; typedef E* iterator;
typedef const E* const_iterator; typedef const E* const_iterator;
......
...@@ -93,9 +93,11 @@ class IteratorFacade { ...@@ -93,9 +93,11 @@ class IteratorFacade {
* this and the `operator==(D const&) const` method above. * this and the `operator==(D const&) const` method above.
*/ */
template <class D2> template <
typename std::enable_if<std::is_convertible<D, D2>::value, bool>::type class D2,
operator==(D2 const& rhs) const { std::enable_if_t<!std::is_same<D, D2>::value, int> = 0,
std::enable_if_t<std::is_convertible<D, D2>::value, int> = 0>
bool operator==(D2 const& rhs) const {
return D2(asDerivedConst()) == rhs; return D2(asDerivedConst()) == rhs;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment