Issue
Consider the following code snippet:
#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!
}
When trying to compile with GCC11.1 (with -std=c++2a
), it attempts to select the compiler-generated operator=
, which is deleted, and fails. The previous GCC versions successfully build this code.
To my understanding, the implicitly-generated deleted operator=
is not viable, so the operator template should be selected. Is it a GCC bug or am I missing something?
Solution
It seems like a bug. It looks for templated method on GCC 11.2 but as you mentioned, it sees deleted method on GCC 11.1.
Answered By - Afshin Answer Checked By - Marie Seifert (WPSolving Admin)