考虑以下代码片段:
#include <utility>
struct test {
template <class Other>
test& operator=(Other&&);
int& i_;
};
int main() {
int i = 0;
test t1{i}, t2{i};
t1 = std::move(t2); // tries to select the implicitly-declared one!
}
尝试使用 GCC11.1 (with -std=c++2a
) 进行编译时,它会尝试选择编译器生成的operator=
,它被删除并失败。以前的 GCC 版本成功地构建了这个代码。
据我了解,隐式生成的deleteoperator=
是不可行的,所以应该选择算子模板。是 GCC 错误还是我遗漏了什么?