https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87063
Bug ID: 87063 Summary: Const subobject with const assignment operator, but operator anyway deleted Product: gcc Version: 9.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: wandersys at aim dot com Target Milestone: --- Hello! Here is an example: class bar { public: bar() {} bar const & operator=(bar const &) const { return *this; } }; class foo { bar const v; }; int main() { foo a; a = foo(); } Here are the relevant points of the standard: ------ 7) A defaulted copy/move assignment operator for class X is defined as deleted if X has: (7.1) a variant member with a non-trivial corresponding assignment operator and X is a union-like class, or (7.2) a non-static data member of const non-class type (or array thereof), or (7.3) a non-static data member of reference type, or (7.4) a direct non-static data member of class type M (or array thereof) or a direct base class M that cannot be copied/moved because overload resolution, as applied to find M's corresponding assignment operator, results in an ambiguity or a function that is deleted or inaccessible from the defaulted assignment operator. ------ Thus, the operator can be `deleted` because of clause 7.4, which relies on overload resolution rules. If we remove the const qualification from the assignment operator, then this clause will be executed, since we cannot allow assignment overloading for a constant object (in this way). Currently, by adding the const-qualification of the operator, I hope to disable this rule because overload resolution becomes possible. However, the compiler forbids me. This code works fine in vc++ and clang, but not in gcc.