[LLVMbugs] [Bug 21481] New: Overload is incorrectly ignored

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Nov 4 14:45:20 PST 2014


http://llvm.org/bugs/show_bug.cgi?id=21481

            Bug ID: 21481
           Summary: Overload is incorrectly ignored
           Product: clang
           Version: 3.5
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: graeser at mi.fu-berlin.de
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 13290
  --> http://llvm.org/bugs/attachment.cgi?id=13290&action=edit
Test case failing with clang-3.5. Compile with -std=c++11

Under certain conditions clang ignores a function overload due to a
substitution failure although substitution should succeed. Suppose you have

  template<class... T>
  struct Foo
  {};

  template<class T0, class... T>
  struct Foo<T0, T...>
  {
    typedef T0 First;
  };

and two overloaded functions selected using enable_if

  template<class C, class... T,
    typename std::enable_if<std::is_same<C, Foo<> >::value, int>::type =0>
  int bar()
  {
      return 0;
  }

  template<class C, class... T,
    typename std::enable_if<!(std::is_same<C, Foo<> >::value), int>::type =0>
  auto bar()
    -> decltype(typename C::First()) // This should be OK by SFINAE
  {
      return 0;
  }

Then substitution of C::First should work for C=Foo<int>. However clang rejects
bar<Foo<int>, char>(). Surprisingly the overload is used if the additional char
parameter is omitted or if an instance of Foo<int> is created in main().

A test case that fails with clang-3.5 is attached. Notice that the variadic
templates seem to be necessary to trigger the problem.

Side note: gcc-4.8 accepts the code.

-- 
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/20141104/839cc73e/attachment.html>


More information about the llvm-bugs mailing list