[llvm-bugs] [Bug 49615] New: std::optional does not work well with std::is_convertible when used with void

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Mar 17 09:00:58 PDT 2021


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

            Bug ID: 49615
           Summary: std::optional does not work well with
                    std::is_convertible when used with void
           Product: libc++
           Version: 11.0
          Hardware: Other
                OS: other
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: contact at jpboivin.me
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com

Hello,

libc++ seems to have an implementation of std::optional that interacts badly
with std::is_convertible when trying to detect whether void is convertible to
an std::optional in an std::enable_if context.

We encountered the issue only on platforms using std::optional from libc++.
Other implementations (libstdc++, MSVC STL, Dinkumware, STX backport) are fine.

It can be easily reproduced with this code:
https://godbolt.org/z/KPqWMz


Here's the extracted error from Clang:

/opt/compiler-explorer/clang-11.0.1/bin/../include/c++/v1/optional:610:45:
error: cannot form a reference to 'void'
          return is_constructible_v<_Tp, _Up&&> &&
                                            ^
/opt/compiler-explorer/clang-11.0.1/bin/../include/c++/v1/optional:711:47:
note: in instantiation of function template specialization
'std::__1::optional<std::__1::basic_string<char, std::__1::char_traits<char>,
std::__1::allocator<char>>>::_CheckOptionalArgsConstructor::__enable_implicit<void>'
requested here
        _CheckOptionalArgsCtor<_Up>::template __enable_implicit<_Up>()
                                              ^
/opt/compiler-explorer/clang-11.0.1/bin/../include/c++/v1/optional:714:15:
note: while substituting prior template arguments into non-type template
parameter [with _Up = void]
    constexpr optional(_Up&& __v)
              ^~~~~~~~~~~~~~~~~~~
/opt/compiler-explorer/clang-11.0.1/bin/../include/c++/v1/type_traits:1739:66:
note: while substituting deduced template arguments into function template
'optional' [with _Up = void, $1 = (no value)]
    : public integral_constant<bool, __is_convertible_to(_T1, _T2)> {};
                                                                 ^
<source>:12:24: note: in instantiation of template class
'std::__1::is_convertible<void, std::__1::optional<std::__1::basic_string<char,
std::__1::char_traits<char>, std::__1::allocator<char>>>>' requested here
std::enable_if_t<!std::is_convertible<TOther, TValue>::value, int> foo(const
TValue& value)

-- 
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/20210317/a30c7027/attachment-0001.html>


More information about the llvm-bugs mailing list