Opened 6 years ago

Last modified 4 months ago

#133 new enhancement

Better signature for copy constructors.

Reported by: Thierry Delisle Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:
Cc:

Description (last modified by ajbeach)

Copy constructors now have a weird C copy as a parameter. This is due to historical reasons and should use const reference instead.

I.e. this:

void ?{}(char &, char);
char ?=?(char &, char);

Instead of

void ?{}(char &, char const &);
char const & ?=?(char &, char const &); 

Attachments (1)

copy-update.diff (15.4 KB ) - added by ajbeach 4 months ago.
Diff from attempt to make this change.

Download all attachments as: .zip

Change History (4)

comment:1 by ajbeach, 7 months ago

Description: modified (diff)

There was a typo in the original copy assignment signature.

After a discussion about wanting the return value of an assignment to be value like, it was agreed that we should change it to be a constant reference. You could still take the address (unless a check is added to prevent it) but it is logically closer to a value.

There was some talk of allowing different signatures be used for different types (for instance, C primitive types could accept and return values) but this interferes with polymorphism and properly lowering from Cforall to C in the last stages of the compiler should take care of performance issues in the remaining cases.

If we allowed operators to not be 1-to-1 with the underlying functions (which is a big change), then we could translate "a = b" into "?=?(a, b), a", that is to say, have the operator return void and provide the return value by comma expression. This forces the behaviour to be consistent, means the user does not have to worry about it and may give more control to the optimizer.

comment:2 by ajbeach, 7 months ago

Description: modified (diff)

by ajbeach, 4 months ago

Attachment: copy-update.diff added

Diff from attempt to make this change.

comment:3 by ajbeach, 4 months ago

I am attaching my attempt to make this change. It does not work, it never worked and now there is also an infinite loop that I do not recall being there when I was working on it actively. It should be enough to help whoever picks it up later.

Note: See TracTickets for help on using tickets.