<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 - cosntexpr constructor breaks out expression SFINAE"
   href="https://bugs.llvm.org/show_bug.cgi?id=42330">42330</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>cosntexpr constructor breaks out expression SFINAE
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>lichray@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>Created <span class=""><a href="attachment.cgi?id=22124" name="attach_22124" title="reproduce">attachment 22124</a> <a href="attachment.cgi?id=22124&action=edit" title="reproduce">[details]</a></span>
reproduce

Clang does not compile the following program:

#include <type_traits>

struct A {};
struct B {};

template <class T>
struct MyPtr {
  MyPtr() = default;
  template <class U>
  constexpr
  MyPtr(MyPtr<U> v) : ptr_(v.ptr_) {}

  T* ptr_;
};

template <class T>
struct __identity { using type = T; };

template <class... _Types>
struct __overload;

template <>
struct __overload<> { void operator()() const; };

template <class _Tp, class... _Types>
struct __overload<_Tp, _Types...> : __overload<_Types...> {
  using __overload<_Types...>::operator();
  static auto __test(_Tp (&&)[1]) -> __identity<_Tp>;

  template <class _Up>
  auto operator()(_Tp, _Up&& __t) const
    -> decltype(__test({ std::forward<_Up>(__t) }));
};

template <class _Tp, class... _Types>
using __best_match_t =
  typename std::invoke_result_t<__overload<_Types...>, _Tp, _Tp>::type;

void test() {
  using t = __best_match_t<MyPtr<A>, MyPtr<A>, MyPtr<B>>;
}


<source>:11:23: error: cannot initialize a member subobject of type 'B *' with
an lvalue of type 'A *'
  MyPtr(MyPtr<U> v) : ptr_(v.ptr_) {}
                      ^    ~~~~~~
<source>:32:26: note: in instantiation of function template specialization
'MyPtr<B>::MyPtr<A>' requested here
    -> decltype(__test({ std::forward<_Up>(__t) }));
                         ^
[...]/include/c++/v1/type_traits:4425:23: note: while substituting deduced
template arguments into function template 'operator()' [with _Up = MyPtr<A>]


Essentially it is saying that a constexpr constructor is called and failed
during substitution, but that shouldn't happen.  What should happen though is
MyPtr<A> being considered convertible to MyPtr<B>, but it's a worse match. 
MSVC gives the right answer.

Commenting out the `constexpr` on line 10 fixes this issue.</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>