<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 --- - clang C++ error passing an std::function to std::stable_sort with --std=c++14"
href="https://llvm.org/bugs/show_bug.cgi?id=27244">27244</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang C++ error passing an std::function to std::stable_sort with --std=c++14
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.8
</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>C++14
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>malcolm.parsons@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Clang reports an error when compiling this code as C++14.
Clang reports no errors when compiling it as C++11.
GCC reports no errors for C++11 or C++14.
$ cat functiontest.cpp
#include <algorithm>
#include <functional>
#include <vector>
class Foo
{
};
void sortMyVector(std::vector<Foo>& foos,
std::function<bool(const Foo&, const Foo&)> fn)
{
std::stable_sort(begin(foos), end(foos), fn);
}
$ g++ --version
g++ (GCC) 5.3.0
...
$ clang++ --version
clang version 3.8.0 (tags/RELEASE_380/final)
...
$ g++ -c --std=c++11 functiontest.cpp
$ g++ -c --std=c++14 functiontest.cpp
$ clang++ -c --std=c++11 functiontest.cpp
$ clang++ -c --std=c++14 functiontest.cpp
In file included from functiontest.cpp:1:
In file included from
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/algorithm:61:
In file included from
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_algobase.h:71:
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/predefined_ops.h:123:31:
error:
indirection requires pointer operand ('Foo' invalid)
{ return bool(_M_comp(*__it1, *__it2)); }
^~~~~~
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/functional:1981:27:
note: in
instantiation of function template specialization
'__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const Foo &, const Foo
&)>
>::operator()<Foo, Foo>' requested here
using _Invoke = decltype(__callable_functor(std::declval<_Functor&>())
^
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/functional:1990:2:
note: in
instantiation of template type alias '_Invoke' requested here
using _Callable
^
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/functional:2057:30:
note: in
instantiation of template type alias '_Callable' requested here
typename = _Requires<_Callable<_Functor>, void>>
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/functional:2058:2:
note: in
instantiation of default argument for
'function<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const Foo &,
const Foo &)> > >'
required here
function(_Functor);
^~~~~~~~
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/predefined_ops.h:130:14:
note:
while substituting deduced template arguments into function template
'function' [with _Functor =
__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (const Foo &, const
Foo &)> >, $1 = (no value)]
{ return _Iter_comp_iter<_Compare>(__comp); }
^
gcc-5.3.0/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/../../../../include/c++/5.3.0/bits/stl_algo.h:4933:27:
note: in
instantiation of function template specialization
'__gnu_cxx::__ops::__iter_comp_iter<std::function<bool (const Foo &, const Foo
&)> >'
requested here
__gnu_cxx::__ops::__iter_comp_iter(__comp));
^
functiontest.cpp:12:10: note: in instantiation of function template
specialization 'std::stable_sort<__gnu_cxx::__normal_iterator<Foo *,
std::vector<Foo, std::allocator<Foo> > >, std::function<bool (const Foo
&, const Foo &)> >' requested here
std::stable_sort(begin(foos), end(foos), fn);
^
1 error generated</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>