【问题标题】:Implicitly-declared boost::iostreams::mapped_file_source is deprecated不推荐使用隐式声明的 boost::iostreams::mapped_file_source
【发布时间】:2020-05-24 01:08:33
【问题描述】:

我正在定义一个结构如下:

struct memory_dump {
    filesystem::path path;
    boost::iostreams::mapped_file_source mapped_file;
    memory_dump_type type;
    long long int offset;
};

但是,gcc 会生成以下警告:

warning: implicitly-declared ‘boost::iostreams::mapped_file_source& boost::iostreams::mapped_file_source::operator=(const boost::iostreams::mapped_file_source&)’ is deprecated [-Wdeprecated-copy]
   39 | struct memory_dump {
      |        ^~~~~~~~~~~

只有在将我的Boost 版本从1.62.0 左右升级到1.72.0 后才会出现此警告。我重新搜索了警告,但没有找到有关此特定 Boost 类、生成警告的原因以及如何修复它的任何信息。我的目标是存储mapped_file_source 的实例,以便我可以有效地访问内存映射文件的内容。

【问题讨论】:

  • 你知道 deprecated 是什么意思吗?
  • @sweenish:是的。这意味着它不应该再使用了。但是应该改用什么呢?

标签: c++ gcc boost memory-mapped-files


【解决方案1】:

你可以在这里看到:https://en.cppreference.com/w/cpp/language/copy_assignment

隐式定义的复制赋值运算符的生成是 如果 T 具有用户声明的析构函数,则弃用(C++11 起)或 用户声明的复制构造函数。

在 boost 1.72 中就是这样,你可以看到:

    // Copy Constructor
    mapped_file_source(const mapped_file_source& other);

boost\iostreams\device\mapped_file.hpp 的第 187 行有这个复制构造函数

【讨论】:

  • 这很好,但您是否也有建议如何修复我的代码以使其合规?
  • 我相信有责任推动开发人员为即将发布的版本解决此警告问题。你的代码是合规的,boost 代码是不合规的。但是,您可以通过几种不同的方式来缓解这种情况,例如删除复制构造函数,或者自己实现赋值运算符。
  • 代码也已经合规了。它将来可能会停止合规,这就是您收到弃用警告的原因
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-10-14
  • 2020-08-12
  • 1970-01-01
  • 2013-09-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多