c++ - gcc 4.9.2编译错误: AssetLinkData

标签 c++ gcc

尝试编译下面包含的程序时,出现以下错误。程序中应该修改什么才能成功编译? 看起来 GCC 4.9.2 无法将一些 noexcept 移动构造函数实现为“=default”。

导致问题的线路是: AssetLinkData::AssetLinkData(AssetLinkData&& other) noexcept = default;


COMPILATION ERROR: FAILED: obj/browser/asset_link_data.o g++ -MMD -MF (I removed many more flags)

asset_link_data.cc: error: function 'password_manager::AssetLinkData::AssetLinkData(password_manager::AssetLinkData&&)' defaulted on its redeclaration with an exception-specification that differs from the implicit declaration 'password_manager::AssetLinkData::AssetLinkData(password_manager::AssetLinkData&&)' AssetLinkData::AssetLinkData(AssetLinkData&& other) noexcept = default;


源代码:

#include "asset_link_data.h"

#include <algorithm>

#include <utility>

#include "base/json/json_reader.h"

#include "base/json/json_value_converter.h"

#include "base/values.h"

namespace password_manager { namespace {

constexpr char kGetLoginsRelation[] =
    "delegate_permission/common.get_login_creds"; constexpr char kWebNamespace[] = "web";

}  // namespace

AssetLinkData::AssetLinkData() = default;

AssetLinkData::AssetLinkData(AssetLinkData&& other) noexcept = default;

AssetLinkData::~AssetLinkData() = default; AssetLinkData& AssetLinkData::operator=(AssetLinkData&& other) = default;  
}  // namespace password_manager

下面我添加了 asset_link_data.h 的内容:

#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_DATA_H_
#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_DATA_H_

#include <string>
#include <vector>

#include "base/macros.h"
#include "url/gurl.h"

namespace password_manager {

// The class parses an asset link file. The spec for the format is
// https://github.com/google/digitalassetlinks/blob/master/well-known/details.md
// The class cares only about two types of statements:
// - includes. Those are just a reference to a file to be loaded and parsed.
// - "get_login_creds" permission to a web page. That means that the target is
//   allowed to get the credentials saved for the source.
// Only HTTPS URLs are taken into account.
class AssetLinkData {
 public:
  AssetLinkData();
  AssetLinkData(AssetLinkData&& other) noexcept;
  ~AssetLinkData();

  AssetLinkData& operator=(AssetLinkData&& other);

  bool Parse(const std::string& data);

  const std::vector<GURL>& includes() const { return includes_; }
  const std::vector<GURL>& targets() const { return targets_; }

 private:
  std::vector<GURL> includes_;
  std::vector<GURL> targets_;

  DISALLOW_COPY_AND_ASSIGN(AssetLinkData);
};

}  // namespace password_manager
#endif  // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_SITE_AFFILIATION_ASSET_LINK_DATA_H_

最佳答案

错误信息很清楚:

defaulted on its redeclaration with an exception-specification that differs from the implicit declaration

您已要求编译器继续按其本来的方式定义构造函数,但您要求将构造函数设置为noexcept。 .. 并且默认创建的构造函数不是 noexcept

要解决此问题,您需要删除 noexcept 说明符:

AssetLinkData::AssetLinkData(AssetLinkData&& other) = default;

或者,如果你想要一个 no-except 说明符,你需要用老式的方式手工制作它:

AssetLinkData::AssetLinkData(AssetLinkData&& other) noexcept
: includes_(std::move(other.includes_))
, targets_ (std::move(other.targets_ ))
{}

关于c++ - gcc 4.9.2编译错误: AssetLinkData,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47018465/

相关文章:

c - 中断处理程序在真实计算机上不起作用

c++ - 有没有办法在运行特定测试后停止 GoogleTest,无论它通过还是失败?

c++ - 如何在MFC 的CScrollView 类中制作不可见的滚动条?

c++ - 传递对 std::ifstream 的引用作为参数

linux - gcc -llibname 和操作系统如何找到 lib 路径?

c++ - 如何将临时对象作为非常量引用传递给成员函数?

c++ - g++ undefined reference 虽然包含所有文件

c++ - 为什么抛出引用调用复制构造函数的异常?

c++ - 错误 : export ordinal too large: 104116

c - 如何在 gcc 中使用编译指示(或其他方式)指定 -march=native