c++ - 在 Clang 上禁用 "deletion of copy constructor when move constructor is avaliable"

标签 c++ c++11 clang clang++

在 StackOverflow 上查看,我发现在 Clang++ 上,当使用 C++11 标准时,如果您已经为您的类定义了一个移动构造函数,隐式构造函数生成将被禁用,即复制构造函数被“显式删除”。

有什么办法可以禁止这种行为吗?

此外,这种行为是否标准化?因为我在 GCC 中没有相同的行为。

最佳答案

Is there any way to disable this behavior?

没有。但您始终可以:

A(const A&) = default;

虽然我不确定 clang 目前是否完全实现了默认的复制构造函数。

Also, is this behavior standardized?

是的。 [class.copy]/p7:

If the class definition does not explicitly declare a copy constructor, one is declared implicitly. If the class definition declares a move constructor or move assignment operator, the implicitly declared copy constructor is defined as deleted; ...

...

Because I don't have the same behavior in GCC.

哪个版本?我猜想最新的 gcc 版本与 clang 具有相同的行为。但我没有它可供试验。

关于c++ - 在 Clang 上禁用 "deletion of copy constructor when move constructor is avaliable",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8797820/

相关文章:

c++ - 未优化的 clang++ 代码在普通的 main() 中生成不需要的 "movl $0, -4(%rbp)"

xcode - 如何解决损坏的 clang : missing stdlib. h 的问题

c++ - 如何在 C++ 中删除重整

c++ - 如何在不记录核心转储或错误的情况下调试意外进程终止

c++ - 使用用户定义的文字初始化 constexpr 数组

c++ - 在成员函数的默认参数中使用强类型枚举的成员

clang - 如何将 clang-cl 设置为 c++14 或 c++1z?

c++ - fstream 的奇怪问题。不能存储成员变量具有特定值的对象

c++ - 条件变量 - 等待/通知竞争条件

c++ - Microsoft 是否有一个网页保留了在最新 VC++ 中实现的 C++11 功能的最新列表?