This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/38796] New: [c++0x] defaulted operator= with non-default return type accepted


The following invalid code is accepted on the trunk:

========================================
struct A
{
  void operator= (const A&) = default;
};
========================================

Because the return type is not "A&", but "void" the operator=
cannot be the defaulted.

In fact GCC silently changes the return type, as the following code
snippet is accepted:

========================================
struct A
{
  void operator= (const A&) = default;
};

void foo()
{
  A a, b, c;
  a = b = c;
}
========================================

When I remove the default, I get a correct error message:

bug.cc: In function 'void foo()':
bug.cc:9: error: no match for 'operator=' in 'a = b.A::operator=(((const
A&)((const A*)(& c))))'
bug.cc:3: note: candidates are: void A::operator=(const A&)

This is probably related to PR38649.


-- 
           Summary: [c++0x] defaulted operator= with non-default return type
                    accepted
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, monitored
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reichelt at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38796


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]