<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::bind does invoke constexpr functions two times with different parameter types"
href="https://llvm.org/bugs/show_bug.cgi?id=30560">30560</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>std::bind does invoke constexpr functions two times with different parameter types
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>3.9
</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>benni.buch@gmail.com
</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>My example is based on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - std::bind const-qualifying bound arguments captured by value when compiled as C++14"
href="show_bug.cgi?id=23141">https://llvm.org/bugs/show_bug.cgi?id=23141</a>
//--------> Code
#include <functional>
#include <type_traits>
struct Foo{
template < typename U >
void operator()(U&& u)const{
static_assert(std::is_same< U, int& >::value, "");
}
};
struct Bar{
template < typename U >
constexpr void operator()(U&& u)const{
static_assert(std::is_same< U, int& >::value, "");
}
};
int main(){
std::bind(Foo(), 42)(); // OK without constexpr
std::bind(Bar(), 42)(); // Error with constexpr
}
//<-------- Code End
<span class="quote">>$ clang++ -stdlib=libc++ -std=c++1z -o test test.cpp </span >
-------> Output
test.cpp:15:3: error: static_assert failed ""
static_assert(std::is_same< U, int& >::value, "");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4287:23:
note: in instantiation of function template specialization
'Bar::operator()<const int &>' requested here
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4304:9:
note: while substituting deduced template arguments into function template
'__invoke' [with _Fp = const Bar, _Args = <const int &>]
_VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2149:31:
note: in instantiation of template class 'std::__1::__invokable_r<void, const
Bar, const int &>' requested here
static const bool value = __invokable<_Fp,
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2154:18:
note: in instantiation of template class
'std::__1::__is_valid_bind_return<const Bar, const std::__1::tuple<int>,
std::__1::tuple<> >' requested here
bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2260:18:
note: in instantiation of default argument for '__bind_return<const Bar, const
std::__1::tuple<int>, std::__1::tuple<> >' required here
typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:22:22: note: while substituting deduced template arguments into
function template 'operator()' [with _Args = <>]
std::bind(Bar(), 42)(); // Error with constexpr
^
1 error generated.
<------- Output End
The problem is that '_Args' is 'const int &', but it should be 'int&'. If I
force the static_assert to fail by checking if 'U' equals 'void', I get two
different substituten paths:
//--------> Code
#include <functional>
#include <type_traits>
struct Bar{
template < typename U >
constexpr void operator()(U&& u)const{
static_assert(std::is_same< U, void >::value, "");
}
};
int main(){
std::bind(Bar(), 42)();
}
//<-------- Code End
<span class="quote">>$ clang++ -stdlib=libc++ -std=c++1z -o test test.cpp </span >
-------> Output
test.cpp:9:3: error: static_assert failed ""
static_assert(std::is_same< U, void >::value, "");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4287:23:
note: in instantiation of function template specialization 'Bar::operator()<int
&>' requested here
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4304:9:
note: while substituting deduced template arguments into function template
'__invoke' [with _Fp = Bar, _Args = <int &>]
_VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2142:31:
note: in instantiation of template class 'std::__1::__invokable_r<void, Bar,
int &>' requested here
static const bool value = __invokable<_Fp,
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2154:18:
note: in instantiation of template class 'std::__1::__is_valid_bind_return<Bar,
std::__1::tuple<int>, std::__1::tuple<> >' requested here
bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2251:18:
note: in instantiation of default argument for '__bind_return<Bar,
std::__1::tuple<int>, std::__1::tuple<> >' required here
typename __bind_return<_Fd, _Td, tuple<_Args&&...> >::type
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:15:22: note: while substituting deduced template arguments into
function template 'operator()' [with _Args = <>]
std::bind(Bar(), 42)();
^
test.cpp:9:3: error: static_assert failed ""
static_assert(std::is_same< U, void >::value, "");
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4287:23:
note: in instantiation of function template specialization
'Bar::operator()<const int &>' requested here
_LIBCPP_INVOKE_RETURN(_VSTD::forward<_Fp>(__f)(_VSTD::forward<_Args>(__args)...))
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/type_traits:4304:9:
note: while substituting deduced template arguments into function template
'__invoke' [with _Fp = const Bar, _Args = <const int &>]
_VSTD::__invoke(_VSTD::declval<_Fp>(), _VSTD::declval<_Args>()...));
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/__config:451:15: note:
expanded from macro '_VSTD'
#define _VSTD std::_LIBCPP_NAMESPACE
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2149:31:
note: in instantiation of template class 'std::__1::__invokable_r<void, const
Bar, const int &>' requested here
static const bool value = __invokable<_Fp,
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2154:18:
note: in instantiation of template class
'std::__1::__is_valid_bind_return<const Bar, const std::__1::tuple<int>,
std::__1::tuple<> >' requested here
bool = __is_valid_bind_return<_Fp, _BoundArgs, _TupleUj>::value>
^
/media/data/programme/llvm-3.9.0/bin/../include/c++/v1/functional:2260:18:
note: in instantiation of default argument for '__bind_return<const Bar, const
std::__1::tuple<int>, std::__1::tuple<> >' required here
typename __bind_return<const _Fd, const _Td, tuple<_Args&&...> >::type
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test.cpp:15:22: note: while substituting deduced template arguments into
function template 'operator()' [with _Args = <>]
std::bind(Bar(), 42)();
^
2 errors generated.
<------- Output End
I'm working with the standard release of LLVM 3.9.0 from llvm.org.
clang version 3.9.0 (tags/RELEASE_390/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /media/data/programme/llvm-3.9.0/bin</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>