https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96803

            Bug ID: 96803
           Summary: std::tuple chooses wrong constructor for
                    uses-allocator construction
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

#include <tuple>
#include <memory>

struct X
{
  using allocator_type = std::allocator<int>;

  X(X&&) { }
  X(std::allocator_arg_t, const allocator_type&, X&&) { }

  explicit X(int) { }
  explicit X(int, allocator_type) { }
};

int main()
{
  std::tuple<int> o(0);
  std::tuple<X> ok(o);
  std::tuple<X> nok(std::allocator_arg, std::allocator<int>(), o);
}

The last line of main fails:

In file included from tup.C:1:
/home/jwakely/gcc/10/include/c++/10.2.1/tuple: In instantiation of
'std::_Head_base<_Idx, _Head, true>::_Head_base(std::__uses_alloc1<_Alloc>,
_UHead&&) [with _Alloc = std::allocator<int>; _UHead = const int&; long
unsigned int _Idx = 0; _Head = X]':
/home/jwakely/gcc/10/include/c++/10.2.1/tuple:421:43:   required from
'std::_Tuple_impl<_Idx, _Head>::_Tuple_impl(std::allocator_arg_t, const
_Alloc&, const std::_Tuple_impl<_Idx, _UHead>&) [with _Alloc =
std::allocator<int>; _UHead = int; long unsigned int _Idx = 0; _Head = X]'
/home/jwakely/gcc/10/include/c++/10.2.1/tuple:775:70:   required from
'std::tuple<_Elements>::tuple(std::allocator_arg_t, const _Alloc&, const
std::tuple<_Args2 ...>&) [with _Alloc = std::allocator<int>; _UElements =
{int}; bool _Valid = true; typename
std::enable_if<std::tuple<_Elements>::_TCC<_Valid>::__is_explicitly_constructible<const
_UElements& ...>(), bool>::type <anonymous> = false; _Elements = {X}]'
tup.C:19:65:   required from here
/home/jwakely/gcc/10/include/c++/10.2.1/tuple:110:65: error: no matching
function for call to 'X::X(const std::allocator_arg_t&, const
std::allocator<int>&, const int&)'
  110 |  : _Head(allocator_arg, *__a._M_a, std::forward<_UHead>(__uhead)) { }
      |                                                                 ^
tup.C:12:12: note: candidate: 'X::X(int, X::allocator_type)'
   12 |   explicit X(int, allocator_type) { }
      |            ^
tup.C:12:12: note:   candidate expects 2 arguments, 3 provided
tup.C:11:12: note: candidate: 'X::X(int)'
   11 |   explicit X(int) { }
      |            ^
tup.C:11:12: note:   candidate expects 1 argument, 3 provided
tup.C:9:3: note: candidate: 'X::X(std::allocator_arg_t, const allocator_type&,
X&&)'
    9 |   X(std::allocator_arg_t, const allocator_type&, X&&) { }
      |   ^
tup.C:9:50: note:   no known conversion for argument 3 from 'const int' to
'X&&'
    9 |   X(std::allocator_arg_t, const allocator_type&, X&&) { }
      |                                                  ^~~
tup.C:8:3: note: candidate: 'X::X(X&&)'
    8 |   X(X&&) { }
      |   ^
tup.C:8:3: note:   candidate expects 1 argument, 3 provided


The problem is that the __use_alloc call in _Tuple_impl uses the wrong type.

Reply via email to