<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Lambda not convertable to std::function with some templates inbetween"
href="https://bugs.llvm.org/show_bug.cgi?id=42654">42654</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Lambda not convertable to std::function with some templates inbetween
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>-New Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jvapen@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Reproduction: <a href="https://godbolt.org/z/gQqPaO">https://godbolt.org/z/gQqPaO</a> (Clang + MSVC)
Credits to a colleague of mine.
Workaround: <a href="https://godbolt.org/z/zI5umV">https://godbolt.org/z/zI5umV</a> > 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){});
}
<span class="quote">>> ERRORS:</span >
<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</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>