Skip to content

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

@frederick-vs-ja

Description

@frederick-vs-ja

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LWG issue neededA wording defect that should be submitted to LWG as a new issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions