我如何弄清楚为什么我的默认移动赋值运算符与“隐式异常规范”不匹配 背景问题

问题描述

背景

我正在帮助调试代码库。我无法提供有关它的确切细节,但无论如何,这些细节都应该超出 SO 问题的范围,我的实际问题是我如何实际诊断为什么任意 noexcept 函数删除,而不是解决我的代码库特定调试问题。

我得到的错误的(经过处理的)版本如下:

/.../bin/cmake --build /.../cmake-build-debug --target [current_project] -- -j 3
...
Scanning dependencies of target [other_module]
...
Scanning dependencies of target [current_project]
...

#[first instance of any error or warning that has to do with 'other_module']
/.../[current_project]/foo.cpp: In member function ‘void util::Foo::update_size(int32_t,int32_t)’:
/.../[current_project]/foo.cpp:159:70: error: use of deleted function ‘[other_module]::Bar& [other_module]::Bar::operator=([other_module]::Bar&&)’
     m_Bar = createBar(number_generator,width,height);

In file included from /.../[current_project]/foo.h:11,from /.../[current_project]/foo.cpp:6:
/.../[current_project]/external/[other_module]/include/Bar.h:69:27: note: ‘[other_module]::Bar& [other_module]::Bar::operator=([other_module]::Bar&&) noexcept’ is implicitly deleted because its exception-specification does not match the implicit exception-specification ‘’
   Bar& operator=(Bar&& r) noexcept = default;
#[No other instances afterwards 'other_module']
...
gmake[3]: *** [CMakeFiles/[current_project].dir/build.make:278: CMakeFiles/[current_project].dir/foo.cpp.o] Error 1
gmake[2]: *** [CMakeFiles/Makefile2:455: CMakeFiles/[current_project].dir/all] Error 2
gmake[1]: *** [CMakeFiles/Makefile2:462: CMakeFiles/[current_project].dir/rule] Error 2
gmake: *** [Makefile:184: [current_project]] Error 2

请注意,createBar 具有以下擦除签名:

Bar createTracker(NumberGenerator number_generator,int width,int height);

我假设 is implicitly deleted because its exception-specification does not match the implicit exception-specification 意味着有一些不是/不能是 noexcept 的东西,无论是在 Bar 的继承链中还是在成员变量的移动赋值运算符中,导致这成为一个问题。

请注意,other_module 被配置为它自己的目标,并且编译所述目标本身不会显示任何警告或错误

但是,我无法获得 clang 工具或 GCC 来告诉我问题出在哪里。我知道这是导致问题的 noexcept,因为如果我删除它,程序就会编译。 Bar 的精简版。

class Bar : public Baz{
public:

Bar(NumberGenerator number_generator,int height);

Bar(const Bar&) noexcept = default;

Bar(Bar&&) noexcept = default;

Bar& operator=(const Bar& r) noexcept = default;
//offending declaration
Bar& operator=(Bar&& r) noexcept = default;
//working declaration
//Bar& operator=(Bar&& r) = default;

private:
    static bool s_value;

    Bax m_bax;
    Qux m_qux;
    std::vector<Quux> m_quux_list;

    std::vector<Corge> m_corge_list;
};

我想,也许如果我手动实现定义,它会帮助我隔离违规的来源,即使这应该是 GCC 一开始给我的信息。然而,在手动实现它后,我发现......它刚刚编译。没有问题。

//no longer defaulted:
Bar& operator=(Bar&& r) noexcept;
//deFinition:
Bar &
Bar::operator=(Bar &&r) noexcept {
    m_bax = std::move(r.m_bax);
    m_qux = std::move(r.m_qux);
    m_quux_list = std::move(r.m_quux_list);
    m_corge_list = std::move(r.m_corge_list);
    return *this;
}

问题

我实际上可以做些什么(即编译器参数、手动代码测试等...)来找出发生这样的任意“noexcept”冲突的地方?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...