microsoft / microsoft/STL

`<scoped_allocator>`, `<xpolymorphic_allocator.h>`: Pre-C++20 overload set of `construct` might be incorrect

Open
#3,383 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
11.1k
Forks
1.7k
Avg merge
4d 15h
Merged PRs (30d)
22

Description

Describe the bug
This program is well-formed in C++17 (but ill-formed since C++20 due to WG21-P0591), because the overload set of construct was specially designed for std::pair (N4659 [mem.poly.allocator.mem], cppreference).

#include <cstddef>
#include <memory_resource>
#include <type_traits>
#include <utility>

int main()
{
    std::pair<int, int> pr{};
    std::pmr::polymorphic_allocator<std::byte> pa{};

    pa.construct<int, int>(&pr);
}

However, MSVC STL always implements the C++20 overload set of construct, and hence rejects this program in C++17 mode (Godbolt link).

https://github.com/microsoft/STL/blob/73924c1920af92899f7582cd904ea819b9db35bc/stl/inc/xpolymorphic_allocator.h#L261-L270

scoped_allocator_adaptor::construct has exactly the same issue.

https://github.com/microsoft/STL/blob/73924c1920af92899f7582cd904ea819b9db35bc/stl/inc/scoped_allocator#L227-L239

The issue has been present even before implementing WG21-P0591 (#1668). I'm not sure whether this is a bug or an intentional design.

Additional context
LWG-3677 may be related to this if we want consistent behaviors in C++17 & C++20 modes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the C++17 reproducer and inspect the linked overloads in stl/inc/xpolymorphic_allocator.h and stl/inc/scoped_allocator. Compare their behavior with N4659, the cppreference description, and LWG-3677; done means the intended C++17 and C++20 behavior is established and verified for both allocator types.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.