<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/109897>109897</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [libc++] self-defined function named 'print' may cause failure in overload resolution
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc++
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Yuzhiy05
      </td>
    </tr>
</table>

<pre>
    The following function will result in overload resolution failure
```c++
#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
```c++
<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++
```
[godbolt](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,selection:(endColumn:15,endLineNumber:16,positionColumn:15,positionLineNumber:16,selectionStartColumn:15,selectionStartLineNumber:16,startColumn:15,startLineNumber:16),source:'%23include+%3Ciostream%3E%0A%23include+%3Cunordered_map%3E%0A+%0Avoid+print(auto+const+comment,+auto+const%26+map)%0A%7B%0A++++std::cout+%3C%3C+comment+%3C%3C+%22%7B%22%3B%0A++++for+(const+auto+%26pair+:+map)%0A++++++++std::cout+%3C%3C+%22%7B%22+%3C%3C+pair.first+%3C%3C+%22:+%22+%3C%3C+pair.second+%3C%3C+%22%7D%22%3B%0A++++std::cout+%3C%3C+%22%7D%5Cn%22%3B%0A%7D%0A+%0Aint+main()%0A%7B%0A++++std::unordered_map%3Cchar,+int%3E+map%7B%7B!'a!',+27%7D,+%7B!'b!',+3%7D,+%7B!'c!',+1%7D%7D%3B%0A+%0A++++print(%22map%22,+map)%3B%0A+%0A%7D'),l:'5',n:'1',o:'C%2B%2B+source+%231',t:'0')),k:49.259743087306774,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:executor,i:(argsPanelShown:'1',compilationPanelShown:'0',compiler:clang_trunk,compilerName:'',compilerOutShown:'0',execArgs:'',execStdin:'',fontScale:14,fontUsePx:'0',j:1,lang:c%2B%2B,libs:!(),options:'-std%3Dc%2B%2B26+++-stdlib%3Dlibc%2B%2B',overrides:!(),runtimeTools:!(),source:1,stdinPanelShown:'1',wrap:'1'),l:'5',n:'0',o:'Executor+x86-64+clang+(trunk)+(C%2B%2B,+Editor+%231)',t:'0')),header:(),k:50.740256912693226,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4)

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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysGE2P4jj215iLVSixEwIHDiQUmpZmZ1rbs4c9IZM44BknZm2H6t5D__bVs50voHpK6kUo4Of37fflMGPEueV8i9IcpfsF6-xF6e2_u_9exLcoXZxU9W37x4XjWkmp3kR7xnXXllaoFr8JKbHmppMWixarG9dSsQpASnYOpWZCdpqjaI-iHVpF_lsiksPXQwkVbSm7imNEC6GM1Zw1iL4-2-5apSuueXVs2HXAuSlR4asWrUVkzT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