[llvm-bugs] [Bug 30589] New: std::complex with a custom type does not work because of how std::__promote is defined

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Oct 1 13:21:03 PDT 2016


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

            Bug ID: 30589
           Summary: std::complex with a custom type does not work because
                    of how std::__promote is defined
           Product: libc++
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: hfinkel at anl.gov
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

Created attachment 17394
  --> https://llvm.org/bugs/attachment.cgi?id=17394&action=edit
test case

In https://reviews.llvm.org/D18639, 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>
>::type
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));
}

-- 
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/20161001/2a7bc13e/attachment.html>


More information about the llvm-bugs mailing list