<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 - Wrong overload being selected"
href="https://bugs.llvm.org/show_bug.cgi?id=40193">40193</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Wrong overload being selected
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>enhancement
</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>dominique.pelle@gmail.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>This program gives a different output with clang and gcc:
$ cat foo.cpp
#include <cstdio>
#include <cstdint>
#include <string>
#include <boost/variant.hpp>
void foo(const char* s)
{
std::printf("in foo(const char*)\n");
}
void foo(const boost::variant<std::uint64_t, std::string>& v)
{
std::printf("in foo(const boost::variant<std::uint64_t, std::string>&)\n");
}
int main()
{
foo(0);
foo(std::uint64_t(0));
foo(std::uint32_t(0));
foo(NULL);
foo(nullptr);
}
With clang (I tried clang-7.0, clang-6.0, clang-5.0.2, clang-4.0, clang-3.9.1)
it prints:
$ clang++-7 -std=c++11 foo.cpp
$ ./a,out
in foo(const char*)
in foo(const boost::variant<std::uint64_t, std::string>&)
in foo(const boost::variant<std::uint64_t, std::string>&)
in foo(const char*)
in foo(const char*)
With gcc (I tried gcc-8.1.0, gcc-7.4.0, gcc-5.5) it prints:
$ g++-8 -std=c++11 foo.cpp
$ ./a.out
in foo(const char*)
in foo(const char*)
in foo(const char*)
in foo(const char*)
in foo(const char*)
Notice the different overdload functions are being invoked
when using clang or gcc.
I'm not 100% sure, but it looks like a clang bug after
reading <a href="http://www.dcs.bbk.ac.uk/~roger/cpp/week20.htm">http://www.dcs.bbk.ac.uk/~roger/cpp/week20.htm</a>
Furthermore, using <a href="https://godbolt.org/">https://godbolt.org/</a> I see that other
compilers msvc v19 and Intel icc 19.0.1 behave like gcc,
which tends to confirm that it's a problem with clang.
Or is it caused by undefined behavior?</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>