isocpp / isocpp/CppCoreGuidelines

Relax enforcement of rule F.16

Open
#1,784 5 comments 0 reactions 1 assignee View on GitHub

@hsutter is already working on this.

Since May 13, 2021.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

We have implemented an automatic check for the current enforcement of rule F.16:

  • (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 than 2 * sizeof(void*). Suggest passing by value instead.

We have received a lot of comments on this by users. Basically it comes down to 2 objections:

  1. The current enforcement is black or white, either something something must be pass by value or must be pass by reference unless the size is exactly 2 * sizeof(void*). The border between when to pass by value or by reference is not that strict in practice. This should also be reflected in the enforcement rules. E.g. greater than 4 * sizeof(void*) -> pass by reference and less than 1 * sizeof(void*) -> pass by value. If your type is somewhere between these two borders, you are allowed decide for yourself whether to use pass by reference or pass by value.
  2. Passing by reference is always OK. The overhead of passing by reference is negilible. So why not only demanding the first enforcement? This is because passing a huge object by value should certainly be forbidden, whereas passing a small object by reference is not wrong.

What are your thoughts on this?

Regards,

Paul

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.