Skip to content

uses_allocator_construction_args has missing forward declarations #66714

Closed
@dieram3

Description

@dieram3

I was trying to use std::uninitialized_construct_using_allocator which was recently added in libc++, but one of the uses I had failed to compile. The actual problem is with std::uses_allocator_construction_args, so I'll put a simplified example using that instead.

void test()
{
    using vt = std::pair<std::pmr::string, std::pair<std::pmr::string, std::pmr::string>>;

    std::pmr::polymorphic_allocator<vt> alloc;
    std::uses_allocator_construction_args<vt>(alloc, std::piecewise_construct,
                                              std::forward_as_tuple("foo"),
                                              std::forward_as_tuple("bar", "baz"));
}

This works with libstdc++ but fails to compile with libc++. After digging for a while, I found out the problem is that __uses_allocator_construction_args overloads are not forward-declared. In particular,

template <class _Pair, class _Alloc, class _Tuple1, class _Tuple2, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
_LIBCPP_HIDE_FROM_ABI constexpr auto __uses_allocator_construction_args(
const _Alloc& __alloc, piecewise_construct_t, _Tuple1&& __x, _Tuple2&& __y) noexcept {

is declared before

template <class _Pair, class _Alloc, class _Up, class _Vp, __enable_if_t<__is_std_pair<_Pair>, int> = 0>
_LIBCPP_HIDE_FROM_ABI constexpr auto
__uses_allocator_construction_args(const _Alloc& __alloc, _Up&& __u, _Vp&& __v) noexcept {

which is why the instantiation of the first one fails (as it can't find the second declaration).

Godbolt repro: https://godbolt.org/z/WorEzejxW

I'd appreciate a fix. Thanks!

Note: this might be related to #64466

Metadata

Metadata

Labels

libc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.rejects-valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions