用clang和libstdc ++编译错误

时间:2017-06-28 14:03:51

标签: c++ clang libc++

我试图用clang编译一个我们以前用gcc编译的大代码库。

以下代码

#include <queue>
#include <functional>

using T = int*;

using Func = std::function<bool(T const, T const)>;
using PQ = std::priority_queue<T, std::vector<T>, Func>;

PQ GetPQ()
{
    Func comp = [](T l, T r) -> bool { return *l < *r; };
    return PQ(comp);
}

使用

编译得很好
clang++ -S -std=c++14 aaa.cpp -stdlib=libc++

但无法使用

进行编译
clang++ -S -std=c++14 aaa.cpp

这是我得到的错误:

In file included from aaa.cpp:1:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/queue:60:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/deque:60:
In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_algobase.h:71:
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/predefined_ops.h:123:23: error: no matching function for call to object of type 'std::function<bool (int *, int *)>'
        { return bool(_M_comp(*__it1, *__it2)); }
                      ^~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/type_traits:2346:7: note: in instantiation of function template specialization '__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> >::operator()<int *, int *>' requested here
      std::declval<_Fn>()(std::declval<_Args>()...)
      ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/type_traits:2357:24: note: while substituting deduced template arguments into function template '_S_test' [with _Fn = __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> >, _Args =
      (no value)]
      typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
                       ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/type_traits:2362:14: note: in instantiation of template class 'std::__result_of_impl<false, false, __gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> >, int *, int *>' requested here
    : public __result_of_impl<
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/functional:1981:35: note: in instantiation of template class 'std::result_of<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> > (int *, int *)>' requested here
               typename _Res2 = typename result_of<_Func(_ArgTypes...)>::type>
                                         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/functional:2053:30: note: in instantiation of default argument for '_Callable<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> > >' required here
               typename = _Requires<_Callable<_Functor>, void>>
                                    ^~~~~~~~~~~~~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/functional:2054:2: note: in instantiation of default argument for 'function<__gnu_cxx::__ops::_Iter_comp_iter<std::function<bool (int *, int *)> >, void>' required here
        function(_Functor);
        ^~~~~~~~
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.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 (int *, int *)>
      >, $1 = (no value), $2 = (no value)]
    { return _Iter_comp_iter<_Compare>(__comp); }
             ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_heap.h:385:28: note: in instantiation of function template specialization '__gnu_cxx::__ops::__iter_comp_iter<std::function<bool (int *, int *)> >' requested here
                       __gnu_cxx::__ops::__iter_comp_iter(__comp));
                                         ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/stl_queue.h:414:14: note: in instantiation of function template specialization 'std::make_heap<__gnu_cxx::__normal_iterator<int **, std::vector<int *, std::allocator<int *> > >, std::function<bool
      (int *, int *)> >' requested here
      { std::make_heap(c.begin(), c.end(), comp); }
             ^
aaa.cpp:12:12: note: in instantiation of member function 'std::priority_queue<int *, std::vector<int *, std::allocator<int *> >, std::function<bool (int *, int *)> >::priority_queue' requested here
    return PQ(comp);
           ^
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/functional:2195:12: note: candidate function not viable: no known conversion from 'int' to 'int *' for 1st argument; remove *
      _Res operator()(_ArgTypes... __args) const;
           ^
1 error generated.

Clang和libstdc ++版本:

$ clang++ --version
    clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
$ /sbin/ldconfig -p | grep stdc++
    libstdc++.so.6 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libstdc++.so.6
    libstdc++.so.6 (libc6) => /usr/lib/i386-linux-gnu/libstdc++.so.6

我宁愿不切换到libc ++,我认为(如果我错了,请纠正我)这应该有效。可能它只是我使用的版本的兼容性问题,但到目前为止我还没有在互联网上找到任何东西。关于可能出现什么问题的任何想法?

0 个答案:

没有答案