[Bug c++/87531] New: [8/9 Regression] assignment operator does nothing if performed as a call via operator=

nok.raven at gmail dot com gcc-bugzilla@gcc.gnu.org
Fri Oct 5 15:37:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87531

            Bug ID: 87531
           Summary: [8/9 Regression] assignment operator does nothing if
                    performed as a call via operator=
           Product: gcc
           Version: 8.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nok.raven at gmail dot com
  Target Milestone: ---

The regression appeared after 7.3.0 and not later than 8.1.0. I do not have
8.0.0 to test it.

https://godbolt.org/z/jjoZ6t

// main.cpp
struct dummy {};

template <typename T>
struct foo : dummy
{
    foo() : v() {}
    foo(T v_) : v(v_) {}
    void assign(foo const& rhs)
    {
        this->operator=(rhs);     // the assignment does nothing
        //(*this).operator=(rhs); // this one does nothing too
        //*this = rhs;            // this one works as expected
    }

    T v;
};

template <typename T>
struct bar : foo<T>
{
    typedef foo<T> base;
    bar() : base() {}
    bar(T v) : base(v) {}
    bar& operator=(bar const& rhs)
    {
        this->assign( static_cast<base const&>(rhs) ) ;
        return *this ;
    }
};

int main()
{
    bar<int> a, b(123);
    a.assign(b);
    if (a.v != 123) throw "problem!";
}


More information about the Gcc-bugs mailing list