[llvm-bugs] [Bug 42330] New: cosntexpr constructor breaks out expression SFINAE

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 19 09:15:32 PDT 2019


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

            Bug ID: 42330
           Summary: cosntexpr constructor breaks out expression SFINAE
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: lichray 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

Created attachment 22124
  --> https://bugs.llvm.org/attachment.cgi?id=22124&action=edit
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.

-- 
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/20190619/2129b8e8/attachment.html>


More information about the llvm-bugs mailing list