Title
Definition of “copy assignment operator”
Status
nad
Section
11.4.6 [class.copy.assign]
Submitter
Steve Adamczyk

Created on 2006-04-15.00:00:00 last changed 183 months ago

Messages

Date: 2009-03-15.00:00:00

Rationale (March, 2009):

It was decided that cv-qualified and ref-qualified assignment operators should be considered copy assignment operators if they have the required parameter type.

Date: 2008-12-15.00:00:00

Additional note (December, 2008):

The proposed resolution addresses only cv-qualified assignment operators and is silent on ref-qualified versions. However, it would seem that the spirit of the resolution would indicate that a ref-qualified assignment operator would not be considered a copy assignment operator.

There appears to be an emerging idiom that relies on the idea that providing an lvalue-only assignment operator would prevent assignment to rvalues:

    struct A {
      A& operator=(const A&) &; // disable assignemt to rvalue
    };

The resolution should also be reconsidered in light of the use of a const-qualified assignment operator as part of the implementation of a proxy class, where the proxy object itself is constant and should not be changed, but the copy assignment operator would apply to the object to which the proxy object refers.

Date: 2006-11-15.00:00:00

Proposed Resolution (November, 2006):

Change 11.4.5.3 [class.copy.ctor] paragraph 9 as follows:

A user-declared copy assignment operator X::operator= is a non-static non-template non-volatile non-const member function of class X with exactly one parameter of type X, X&, const X&, volatile X& or const volatile X&.

[Drafting note: If a user-declared volatile operator= prevented the implicit declaration of the copy assignment operator, all assignments for objects of the given class (even to non-volatile objects) would pay the penalty for volatile write accesses in the user-declared operator=, despite not needing it.]

Date: 2022-02-18.07:47:23

Is the following a “copy assignment operator?”

    struct A {
        const A& operator=(const A&) volatile;
    };

11.4.5.3 [class.copy.ctor] paragraph 9 doesn't say one way or the other whether cv-qualifiers on the function are allowed. (A similar question applies to the const case, but I avoided that example because it seems so wrong one tends to jump to a conclusion before seeing what the standard says.)

Since the point of the definition of “copy assignment operator” is to control whether the compiler generates a default version if the user doesn’t, I suspect the correct answer is that neither const nor volatile cv-qualification on operator= should be allowed for a “copy assignment operator.” A user can write an operator= like that, but it doesn't affect whether the compiler generates the default one.

History
Date User Action Args
2009-03-23 00:00:00adminsetmessages: + msg2034
2009-03-23 00:00:00adminsetstatus: review -> nad
2009-02-08 00:00:00adminsetmessages: + msg1865
2008-02-03 00:00:00adminsetmessages: + msg1567
2008-02-03 00:00:00adminsetstatus: open -> review
2006-04-15 00:00:00admincreate