Skip to content

F.16 is not consistent with regard to the size limit #2324

@beinhaerter

Description

@beinhaerter

In F.16: For “in” parameters, pass cheaply-copied types by value and others by reference to const the Reason section says (emphasis is mine):

What is “cheap to copy” depends on the machine architecture, but two or three words (doubles, pointers, references) are usually best passed by value. When copying is cheap, nothing beats the simplicity and safety of copying, and for small objects (up to two or three words) it is also faster than passing by reference because it does not require an extra indirection to access from the function.

This could be read as "<= two words" is cheap to copy, ">3 words" is not cheap to copy and ">two words && <=3 words" can be discussed but would normally be considered cheap to copy.

The enforcement section says (emphasis is mine):

(Simple) ((Foundation)) Warn when a parameter being passed by value has a size greater than 2 * sizeof(void*). Suggest using a reference to const instead.
(Simple) ((Foundation)) Warn when a parameter passed by reference to const has a size less or equal than 2 * sizeof(void*). Suggest passing by value instead.

This does not mention three at all, it says the fixed limit is two (<=2 and >2).

I understand both sections and their reasoning. But I think both sections should be consistent. It is hard to understand why the reasoning for the rule says something but the enforcement is stricter than the reasoning. You could now argue with the reason section and still have an analyzer tool that warns that you are doing something you should not do.

If you want to adjust one of the sections, feel free to tell me which way to go and I will be happy to prepare a PR.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions