是否有诊断标志或工具可以
如果编译器删除了显式默认的函数声明,则警告我
?
如果不是,那为什么?被删除的默认成员是否是期望的行为?什么时候和多久发生一次?
细节
我正在使用clang版本5.0.1,但通过最近的MSVC或gcc版本发出警告也可以。
一个简单的例子:
class NotMoveA
{
public:
explicit NotMoveA(Foo f);
~NotMoveA() = default;
NotMoveA(const NotMoveA &) = delete;
NotMoveA(NotMoveA &&other) = default;
NotMoveA &operator=(const NotMoveA &) = delete;
//will B deleted w/o warning:
NotMoveA &operator=(NotMoveA &&other) = default;
// ...
private:
const std::string badDataMemberDisallowingMoveAssignment;
// ...
}
使用
NotMoveA
在一个
std::vector
不动
不是可移动的,我犯了一些错误,我花了很长时间才弄清楚原因。直接针对原因的警告,即删除
= default
功能,会有帮助的。