1

考虑以下代码片段

#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 错误还是我遗漏了什么?

4

1 回答 1

0

这似乎是一个错误。它在 GCC 11.2 上查找模板化方法,但正如您所提到的,它在 GCC 11.1 上看到已删除的方法。

于 2022-01-11T17:40:21.590 回答