std :: forward_as_tuple导致linux上的clang 3.5和libc ++出现编译错误

时间:2015-09-29 08:44:52

标签: c++ clang tuples libc++

以下简单代码

#include <string>
#include <sstream>
#include <memory>
#include <tuple>
#include <map>
#include <cassert>

struct foo {
  foo(std::ostringstream&, std::unique_ptr<int>&&);
};

struct bar  {
  std::map<std::string,foo> map;
  void add(std::string const &name,
           std::ostringstream &str,
           std::unique_ptr<int> &&ptr)
  {
    auto result = map.emplace
      ( std::piecewise_construct,
        std::forward_as_tuple(name),
        std::forward_as_tuple(str,std::move(ptr)) );
    assert(result.second);
  }
};

适用于Mac OSX中安装的gcc和clang。但是,当我使用-stdlib=libc++(在clang 3.2和3.4中很好)时,我在linux系统上遇到了一些clang 3.5的问题,其中库显然是与clang 3.2一起安装的(如何获取llvm的libc ++版本?) ,当编译器给出错误

In file included from test.cc:1: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/string:434: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/algorithm:594: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/memory:599: /cm/shared/apps/llvm/3.2/include/libcxx/tuple:320:11: error: rvalue reference to type 'unique_ptr<[2 * ...]>' cannot bind to lvalue of type 'unique_ptr<[2 * ...]>'
        : value(__t.get())
          ^     ~~~~~~~~~ /cm/shared/apps/llvm/3.2/include/libcxx/tuple:444:8: note: in instantiation of member function 'std::__1::__tuple_leaf<1, std::__1::unique_ptr<int, std::__1::default_delete<int> > &&, false>::__tuple_leaf' requested here struct
__tuple_impl<__tuple_indices<_Indx...>, _Tp...>
       ^ utils2/test.cc:23:13: note: in instantiation of function template specialization 'std::__1::forward_as_tuple<std::__1::basic_ostringstream<char, std::__1::char_traits<char>, std::__1::allocator<char> > &, std::__1::unique_ptr<int, std::__1::default_delete<int> > >' requested here
       std::forward_as_tuple(str,std::move(ptr)));
            ^ In file included from utils2/test.cc:1: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/string:434: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/algorithm:594: In file included from /cm/shared/apps/llvm/3.2/include/libcxx/memory:599: /cm/shared/apps/llvm/3.2/include/libcxx/tuple:321:10: error: static_assert failed "Can not copy a tuple with rvalue reference member"
        {static_assert(!is_rvalue_reference<_Hp>::value, "Can not copy a tuple with rvalue reference member");}
         ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

这里有什么问题,编译器,库或我的代码?我怎样才能避免这个问题(使用给定的编译器/库)?

0 个答案:

没有答案