-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Closed as not planned
Closed as not planned
Copy link
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Description
The following function will result in overload resolution failure
#include <iostream>
#include <unordered_map>
void print(auto const comment, auto const& map)
{
std::cout << comment << "{";
for (const auto &pair : map)
std::cout << "{" << pair.first << ": " << pair.second << "}";
std::cout << "}\n";
}
int main()
{
std::unordered_map<char, int> map{{'a', 27}, {'b', 3}, {'c', 1}};
print("map", map);
}result
<source>:16:5: error: call to 'print' is ambiguous
16 | print("map", map);
| ^~~~~
<source>:4:6: note: candidate function [with comment:auto = const char *, map:auto = std::unordered_map<char, int>]
4 | void print(auto const comment, auto const& map)
| ^
/opt/compiler-explorer/clang-trunk-20240924/bin/../include/c++/v1/print:341:28: note: candidate function [with _Args = <std::unordered_map<char, int> &>]
341 | _LIBCPP_HIDE_FROM_ABI void print(format_string<_Args...> __fmt, _Args&&... __args) {
| ^
1 error generated.options
-std=c++26 -stdlib=libc++
The C++ standard documentation requires that ostream support the inclusion of a std::print(std::ostream&...) , However, libc++ instead includes a complete print header , such as std::print(format_string<_Args...> __fmt, _Args&&... __args), then ADL might cause confusion
I do not want to include the header print, but including iostream might implicitly involve it
Metadata
Metadata
Assignees
Labels
invalidResolved as invalid, i.e. not a bugResolved as invalid, i.e. not a buglibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.