Topic: If no cp ctor, why not def ctor and ass


Author: clamage@Eng.Sun.COM (Steve Clamage)
Date: 1995/05/17
Raw View
In article Dsu@info.physics.utoronto.ca, peter@chinook.physics.utoronto.ca (Peter Berdeklis) writes:
>According to Steve Clamage <clamage@Eng.Sun.COM>:
>> In article 4CC@info.physics.utoronto.ca, peter@chinook.physics.utoronto.ca (Peter Berdeklis) writes:
>>
>> There is no a priori reason to believe that default ctor plus assignment
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> will be correct and the compiler-generated copy ctor will not.
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>> The reverse could be true.
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^
>
>
>I think the reason to believe that the default ctor plus assignment
>will be correct is that you assume that the programmer knew what
>(s)he was doing when the assignment op. was written.

If we assume the programmer is acting purposefully and correctly, and
yet did not write a copy ctor, then we should assume the default copy
semantics are correct. (Otherwise the programmer would have written a
different copy ctor.)

If we *don't* assume the programmer is acting sensibly, why should we
assume *anything* about the correctness of default ctor plus assignment?

We have a simple rule: the default version of any copy just copies
the members. (Either copy-construct, or copy-assign.) If you want
different semantics, you write a function that does what you want.
This rule makes no assumptions about programs or programmers. It's
just a simple rule that has the same semantics for C-like objects
as the C language does. (And that is the origin of the rule.)

I fail to see any advantage in making a special-case assumption that
might not be any better than the simple rule. An argument like "This
special case gives a better answer than the existing rule X% of the
time" seems pointless, unless X is demonstrably near 100.
---
Steve Clamage, stephen.clamage@eng.sun.com