microsoft / microsoft/STL

`<iomanip>`: ADL for the return types of `get_time`/`put_time` looks into the global namespace

Open
#6,048 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Currently, the user-defined overload affects overload resolution. Godbolt link. [ext.manip] arguably disallows this.

#include <iostream>
#include <iomanip>
#include <ctime>

template<class CharT, class Traits, class T>
std::basic_ostream<CharT, Traits>& operator<<(std::basic_ostream<CharT, Traits>& os, T&&) {
    return os << "catch-all\n";
}

int main() {
    std::tm tmv{};
    std::cout << std::put_time(&tmv, "%Y-%M");
}

The reason is that put_time returns _Timeobj<_Elem, const tm*> whose associated namespaces contains the global namespace.

Perhaps the right fix would need to change the return type.

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 by reproducing the Godbolt example and inspect the iomanip implementation of get_time and put_time, along with the linked ext.manip wording. Determine how the return type causes associated-namespace lookup to reach the global namespace. Done means the user-defined catch-all no longer affects overload resolution, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.