<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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 --- - std::complex with a custom type does not work because of how std::__promote is defined"
   href="https://llvm.org/bugs/show_bug.cgi?id=30589">30589</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>std::complex with a custom type does not work because of how std::__promote is defined
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libc++
          </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>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>hfinkel@anl.gov
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, mclow.lists@gmail.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=17394" name="attach_17394" title="test case">attachment 17394</a> <a href="attachment.cgi?id=17394&action=edit" title="test case">[details]</a></span>
test case

In <a href="https://reviews.llvm.org/D18639">https://reviews.llvm.org/D18639</a>, Eric asked if we supporting using
std::complex with custom numeric types. The answer is: mostly. I've attached
the test case I started writing. This compiles with libstdc++, and in fact,
requires a lot less of the custom type than we do (e.g. we require fabs in
addition to abs, scalbn, logb, and many other functions). With libc++, however,
we do it one compilation error which looks like a problem with libc++ itself:

include/c++/v1/complex:1321:39: error: no matching function for call to 'pow'
    complex<_Tp> __z = log(__x + sqrt(pow(__x, _Tp(2)) - _Tp(1)));
...
include/c++/v1/complex:1109:1: note: candidate template ignored: substitution
failure [with _Tp = ct::va
lue, _Up = ct::value]: no type named 'type' in 'std::__1::__promote<ct::value,
ct::value, void>'
pow(const complex<_Tp>& __x, const _Up& __y)

The problem here seems to be that std::__promote, which is defined in
type_traits, only works for types for which __numeric_type<T>::type exists, and
that is only for builtin numeric types. As a result, this template does not
match:

template<class _Tp, class _Up>
inline _LIBCPP_INLINE_VISIBILITY
typename enable_if
<
    is_arithmetic<_Up>::value,
    complex<typename __promote<_Tp, _Up>::type>
<span class="quote">>::type</span >
pow(const complex<_Tp>& __x, const _Up& __y)
{
    typedef complex<typename __promote<_Tp, _Up>::type> result_type;
    return _VSTD::pow(result_type(__x), result_type(__y));
}</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>