microsoft / microsoft/STL

`<memory>` etc.: ADL should be avoided when calling `_Construct_in_place` and its friends

Open
#3,100 1 comment 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

This well-formed program fails to compile with MSVC STL due to unqualified calls to internal functions (which trigger ADL and overly require completeness of related types).

#include <any>
#include <concepts>
#include <functional>
#include <memory>
#include <optional>
#include <variant>

struct Incomplete;

template<class T>
struct Holder {
    T t;
};

using Ptr = Holder<Incomplete>*;

int main()
{
    std::make_shared<Ptr>();
    std::make_shared<Ptr[]>(42);
    std::function<void(Ptr)>{std::identity{}};
    std::any{Ptr{}};
    std::optional<Ptr>{}.emplace();
    std::variant<Ptr>{}.emplace<Ptr>();
}

Godbolt link. (libc++ accepts it correctly)

This is similar to #1596 but touches different library mechanisms, and should be considered as a sub-issue of #140.
Previously, 3 libc++ tests were blocked by this issue:

  • std/utilities/function.objects/func.wrap/func.wrap.func/robust_against_adl.pass.cpp
  • std/utilities/memory/allocator.traits/allocator.traits.members/construct.pass.cpp
  • std/utilities/memory/allocator.traits/allocator.traits.members/destroy.pass.cpp

Perhaps we should _STD-qualify internal function calls used for in-place construction/destruction by default, especially for _Construct_in_place, _Destroy_in_place, and _Voidify_iter (_Voidify_iter was killed when implementing LWG-3870).

  • Issues of variant are fixed by #3148.
  • Issues of any are fixed by #3965.
  • Issues of allocator are fixed by #4373.
  • Issues of shared_ptr are fixed by #4403.
  • Issues of function, etc. are fixed by #4430.
  • Issues of valarray are fixed by #5157.

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 reproducer and the relationship to #140, then review the listed fixes for variant, any, allocator, shared_ptr, and function. Check the named libc++ tests and the remaining internal in-place construction or destruction calls. Done means confirming whether any affected mechanism still lacks the requested qualification and identifying a focused regression test.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.