[llvm-bugs] [Bug 40193] New: Wrong overload being selected

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 1 03:27:49 PST 2019


https://bugs.llvm.org/show_bug.cgi?id=40193

            Bug ID: 40193
           Summary: Wrong overload being selected
           Product: clang
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: dominique.pelle at gmail.com
                CC: blitzrakete at gmail.com, dgregor at apple.com,
                    erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
                    richard-llvm at metafoo.co.uk

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 http://www.dcs.bbk.ac.uk/~roger/cpp/week20.htm

Furthermore, using https://godbolt.org/  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?

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190101/bb7401ee/attachment.html>


More information about the llvm-bugs mailing list