<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Template function gets selected also if a non-template function with appropriate signature exists"
href="https://bugs.llvm.org/show_bug.cgi?id=47967">47967</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Template function gets selected also if a non-template function with appropriate signature exists
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>10.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andrea_iob@hotmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=24099" name="attach_24099" title="Example code that shows the problem.">attachment 24099</a> <a href="attachment.cgi?id=24099&action=edit" title="Example code that shows the problem.">[details]</a></span>
Example code that shows the problem.
In the attached example I'm declaring a template stream (<<) operator, then I'm
declaring a non-template operator.
In my understanding the non-template operator should have priority over the
template version. However, there is a case where the template operator is
selected instead of the non-template one.
When I run the attached example I see the following output:
# clang++ -o test test.cpp
# ./test
Using stream operator directly:
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
Using stream through function 'writeAfter':
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
Using stream through function 'writeBefore':
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> TEMPLATE STREAM OPERATOR
The last call of the function writeBefore is using the template stream operator
instead of the non-template version.
I've tested the example code with clang++ 7.0.1 and 10.0.1 and both give me the
same results.
The "data" and "streamer" namespaces seem to play some role in this behaviour:
if a remove them I get the expected behaviour.
If I compile the example with g++ I get the "correct" output:
# g++ -o test test.cpp
# ./test
Using stream operator directly:
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
Using stream through function 'writeAfter':
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
Using stream through function 'writeBefore':
> NON-TEMPLATE STREAM OPERATOR FOR CLASS OutsideNamespaceData
> NON-TEMPLATE STREAM OPERATOR FOR CLASS data::InsideNamespaceData
Let me know if further details are required.
Thanks.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>