[llvm-bugs] [Bug 27244] New: clang C++ error passing an std::function to std::stable_sort with --std=c++14

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 6 09:29:58 PDT 2016


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

            Bug ID: 27244
           Summary: clang C++ error passing an std::function to
                    std::stable_sort with --std=c++14
           Product: clang
           Version: 3.8
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++14
          Assignee: unassignedclangbugs at nondot.org
          Reporter: malcolm.parsons at gmail.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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

-- 
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/20160406/5479725e/attachment.html>


More information about the llvm-bugs mailing list