1

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?

Igor R.
  • 14,716
  • 2
  • 49
  • 83
  • For me, it looks for `test& test::operator=(test&&)` which is obviously templated one and it fails because it has no definition. If I understand your problem correctly. – Afshin Jan 11 '22 at 17:09
  • @Afshin take a look at the error: "error: use of deleted function 'test& test::operator=(test&&)'". The compiler doesn't care about the definition, as it may exist in another TU. – Igor R. Jan 11 '22 at 17:35
  • it gives me: 'undefined reference to `test& test::operator=(test&&)`'. You can see it here: https://godbolt.org/z/1dTf58jfo – Afshin Jan 11 '22 at 17:37
  • OH!!! it is ok for Gcc 11.2, but it gives error that you mentioned on GCC 11.1. it is probably a bug. – Afshin Jan 11 '22 at 17:39

1 Answers1

0

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.

Afshin
  • 8,839
  • 1
  • 18
  • 53