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.