https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122289
Bug ID: 122289
Summary: std::tuple allocator-extended constructors should use
std::make_obj_using_allocator for each element
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: redi at gcc dot gnu.org
Target Milestone: ---
See the example in https://cplusplus.github.io/LWG/issue4313
I agree with Pablo's comment there: tuple's allocator-extended constructors
should be using std::make_obj_using_allocator, so that uses-allocator
construction works properly for std::pair elements in the std::tuple.
#include <tuple>
#include <utility>
#include <testsuite_hooks.h>
#include <testsuite_allocator.h>
template<typename T>
using Alloc = __gnu_test::uneq_allocator<T>;
struct X
{
using allocator_type = Alloc<int>;
X(int i) : alloc(), i(i) { }
X(std::allocator_arg_t, const allocator_type& alloc, int i)
: alloc(alloc), i(i)
{ }
allocator_type alloc;
int i;
};
using Pair = std::pair<X, X>;
using Tuple = std::tuple<Pair>;
int main()
{
Alloc<int> a(99);
Pair p = std::make_obj_using_allocator<Pair>(a, 1, 2);
VERIFY(p.first.alloc == a);
VERIFY(p.second.alloc == a);
Tuple t(std::allocator_arg, a, {1, 2});
VERIFY(std::get<0>(t).first.alloc == a);
VERIFY(std::get<0>(t).second.alloc == a);
}
This fails:
4313.cc:35: int main(): Assertion 'std::get<0>(t).first.alloc == a' failed.
But if we do uses-allocator construction for each element then we should
construct each element of the pair with the allocator, as happens for the Pair
p.