使用clang编译libstdc++4.4.7和-std=c++0x时会失败

Compiling with clang fails with libstdc++4.4.7 and -std=c++0x

本文关键字:c++0x 失败 -std 编译 clang libstdc++4 使用      更新时间:2023-10-16

我正在尝试使用clang在旧的RHEL5机器上编译一些代码,该机器使用libstdc++4.4.7。当我启用-std=c++0x标志时,我得到:

/usr/lib/gcc/i386-redhat-linux6E/4.4.7/../../../../include/c++/4.4.7/bits/vector.tcc:380:19: error: call to implicitly-deleted copy constructor of
  'value_type' (aka 'std::pair<double, double>')
          value_type __x_copy = __x;
                     ^          ~~~
/usr/lib/gcc/i386-redhat-linux6E/4.4.7/../../../../include/c++/4.4.7/bits/stl_vector.h:851:9: note: in instantiation of member function
  'std::vector<std::pair<double, double>, std::allocator<std::pair<double, double> > >::_M_fill_insert' requested here
  { _M_fill_insert(__position, __n, __x); }

这是我在clang网站上应用补丁(修复了其他错误,但不是这个)之后。当我禁用-std=c++0x它工作正常。听起来补丁可能没有解决所有的问题,这是一个已知的问题,有一个已知的修复?

补丁未完成。

Clang是正确的,代码是错误的:复制构造函数应该被删除,因为std::pair声明了一个移动构造函数,但那是因为Clang正在实现最终的c++ 11规则,GCC 4.4头文件是为了使用GCC 4.4支持的早期版本的c++ 0x草案而编写的

您应该能够通过将此添加到std::pair:

来修复它。
pair(const pair&) = default;
pair& operator=(const pair&) = default;

恢复隐式定义的复制操作,因此Clang不会删除它们。