[llvm-bugs] [Bug 42654] New: Lambda not convertable to std::function with some templates inbetween

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 17 09:26:42 PDT 2019


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

            Bug ID: 42654
           Summary: Lambda not convertable to std::function with some
                    templates inbetween
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jvapen at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Reproduction: https://godbolt.org/z/gQqPaO (Clang + MSVC)
Credits to a colleague of mine.
Workaround: https://godbolt.org/z/zI5umV > replace using statement by:
template<typename T> using Integer = std::conditional_t<std::is_void_v<T>, int,
int>;


// clang++ -std=c++17 -Werror -Wall -stdlib=libc++
#include <type_traits>
#include <functional>
#include <tuple>


template<typename ...Ts>
class Environment final
{
public:

    template<typename T>
    using Integer = int;

    using Function = std::function<void(Integer<Ts>...)>; // expands to
std::function<void(int,int)>
    using MyTuple = std::tuple<Integer<Ts>...>; // expands to
std::function<void(int, int)>

    auto run(Function func) -> void
    {
        auto ints = MyTuple{};
        std::apply(func, ints);
     }
};

int main()
{
    auto env = Environment<int, double>{};
    env.run([](int, int){});

}




>> ERRORS:

<source>:27:13: error: no viable conversion from '(lambda at <source>:27:13)'
to 'Environment::Function' (aka 'function<void (int)>')

    env.run([](int, int){});

            ^~~~~~~~~~~~~~

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:2276:5:
note: candidate constructor not viable: no known conversion from '(lambda at
<source>:27:13)' to 'std::nullptr_t' (aka 'nullptr_t') for 1st argument

    function(nullptr_t) _NOEXCEPT {}

    ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:2277:5:
note: candidate constructor not viable: no known conversion from '(lambda at
<source>:27:13)' to 'const std::__1::function<void (int)> &' for 1st argument

    function(const function&);

    ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:2278:5:
note: candidate constructor not viable: no known conversion from '(lambda at
<source>:27:13)' to 'std::__1::function<void (int)> &&' for 1st argument

    function(function&&) _NOEXCEPT;

    ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:2280:5:
note: candidate template ignored: requirement '__callable<(lambda at
<source>:27:13), false>::value' was not satisfied [with _Fp = (lambda at
<source>:27:13)]

    function(_Fp);

    ^

<source>:27:13: note: candidate function

    env.run([](int, int){});

            ^

<source>:17:23: note: passing argument to parameter 'func' here

    auto run(Function func) -> void

                      ^

In file included from <source>:2:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:497:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/memory:662:

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1377:5:
error: attempt to use a deleted function

    _VSTD::__invoke_constexpr(

    ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/__config:758:15:
note: expanded from macro '_VSTD'

#define _VSTD std::_LIBCPP_ABI_NAMESPACE

              ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1374:26:
note: in instantiation of exception specification for
'__apply_tuple_impl<std::__1::function<void (int)> &, std::__1::tuple<int, int>
&, 0, 1>' requested here

constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,

                         ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1386:12:
note: in instantiation of function template specialization
'std::__1::__apply_tuple_impl<std::__1::function<void (int)> &,
std::__1::tuple<int, int> &, 0, 1>' requested here

    _VSTD::__apply_tuple_impl(

           ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1384:26:
note: in instantiation of exception specification for
'apply<std::__1::function<void (int)> &, std::__1::tuple<int, int> &>'
requested here

constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)

                         ^

<source>:20:14: note: in instantiation of function template specialization
'std::__1::apply<std::__1::function<void (int)> &, std::__1::tuple<int, int>
&>' requested here

        std::apply(func, ints);

             ^

<source>:27:9: note: in instantiation of member function 'Environment<int,
double>::run' requested here

    env.run([](int, int){});

        ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/type_traits:1680:5:
note: '~__nat' has been explicitly marked deleted here

    ~__nat() = delete;

    ^

In file included from <source>:2:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:497:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/memory:662:

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1377:5:
error: attempt to use a deleted function

    _VSTD::__invoke_constexpr(

    ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/__config:758:15:
note: expanded from macro '_VSTD'

#define _VSTD std::_LIBCPP_ABI_NAMESPACE

              ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1386:12:
note: in instantiation of function template specialization
'std::__1::__apply_tuple_impl<std::__1::function<void (int)> &,
std::__1::tuple<int, int> &, 0, 1>' requested here

    _VSTD::__apply_tuple_impl(

           ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1384:26:
note: in instantiation of exception specification for
'apply<std::__1::function<void (int)> &, std::__1::tuple<int, int> &>'
requested here

constexpr decltype(auto) apply(_Fn && __f, _Tuple && __t)

                         ^

<source>:20:14: note: in instantiation of function template specialization
'std::__1::apply<std::__1::function<void (int)> &, std::__1::tuple<int, int>
&>' requested here

        std::apply(func, ints);

             ^

<source>:27:9: note: in instantiation of member function 'Environment<int,
double>::run' requested here

    env.run([](int, int){});

        ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/type_traits:1680:5:
note: '~__nat' has been explicitly marked deleted here

    ~__nat() = delete;

    ^

In file included from <source>:2:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/functional:497:

In file included from
/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/memory:662:

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1386:5:
error: no matching function for call to '__apply_tuple_impl'

    _VSTD::__apply_tuple_impl(

    ^~~~~~~~~~~~~~~~~~~~~~~~~~

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/__config:758:15:
note: expanded from macro '_VSTD'

#define _VSTD std::_LIBCPP_ABI_NAMESPACE

              ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1370:79:
note: expanded from macro '_LIBCPP_NOEXCEPT_RETURN'

#define _LIBCPP_NOEXCEPT_RETURN(...) noexcept(noexcept(__VA_ARGS__)) { return
__VA_ARGS__; }

                                                                             
^~~~~~~~~~~

<source>:20:14: note: in instantiation of function template specialization
'std::__1::apply<std::__1::function<void (int)> &, std::__1::tuple<int, int>
&>' requested here

        std::apply(func, ints);

             ^

<source>:27:9: note: in instantiation of member function 'Environment<int,
double>::run' requested here

    env.run([](int, int){});

        ^

/opt/compiler-explorer/clang-trunk-20190717/bin/../include/c++/v1/tuple:1374:26:
note: candidate template ignored: substitution failure [with _Fn =
std::__1::function<void (int)> &, _Tuple = std::__1::tuple<int, int> &, _Id =
<0, 1>]

constexpr decltype(auto) __apply_tuple_impl(_Fn && __f, _Tuple && __t,

                         ^

4 errors generated.

Compiler returned: 1

-- 
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/20190717/24c28406/attachment-0001.html>


More information about the llvm-bugs mailing list