Skip to content

ctl string const/value tweaks #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2024
Merged

ctl string const/value tweaks #1218

merged 2 commits into from
Jun 16, 2024

Conversation

mrdomino
Copy link
Collaborator

@mrdomino mrdomino commented Jun 15, 2024

The mangled name of a C++ function will typically not vary by const-ness of a by-value parameter; in other words, there is no meaning to a const- qualified by-value parameter in a function prototype. However, the const keyword _does_ matter at function _definition_ time, like it does with a variable declared in the body. So for prototypes, we strip out const for by-value parameters; but for definitions, we leave them alone.

At function definition (as opposed to prototype), we add const to values in parameters by default, unless we’re going to mutate them.

This commit also changes a couple of const string_view& to be simply by- value string_view. A string_view is only two words; it rarely ever makes sense to pass one by reference if it’s not going to be mutated.

mrdomino added 2 commits June 15, 2024 14:32
The mangled name of a C++ function will typically not vary by const-ness
of a by-value parameter; in other words, there is no meaning to a const-
qualified by-value parameter in a function prototype. However, the const
keyword _does_ matter at function _definition_ time, like it does with a
variable declared in the body. So for prototypes, we strip out const for
by-value parameters; but for definitions, we leave them alone.

This commit also changes a couple of const string_view& to be simply by-
value string_view. A string_view is only two words; it rarely ever makes
sense to pass one by reference if it's not going to be mutated.
At function definition (as opposed to prototype), we add const to values
in parameters by default, unless we're going to mutate them.
@mrdomino
Copy link
Collaborator Author

I split out the commit that const-qualifies method definitions, since that might be more contentious - I don't care strongly either way on it, but I've known people who've insisted on it in the past, and it's closer to the thing that you get out of e.g. Rust's defaults (of let being const and let mut being non-const.)

I think the first commit is probably unambiguously desirable.

@mrdomino mrdomino requested a review from jart June 15, 2024 21:56
@mrdomino mrdomino merged commit 0a61ff7 into jart:master Jun 16, 2024
@mrdomino mrdomino deleted the ctl-const branch June 16, 2024 01:09
mrdomino added a commit that referenced this pull request Jun 16, 2024
The mangled name of a C++ function will typically not vary by const-ness
of a by-value parameter; in other words, there is no meaning to a const-
qualified by-value parameter in a function prototype. However, the const
keyword _does_ matter at function _definition_ time, like it does with a
variable declared in the body. So for prototypes, we strip out const for
by-value parameters; but for definitions, we leave them alone.

At function definition (as opposed to prototype), we add const to values
in parameters by default, unless we’re going to mutate them.

This commit also changes a couple of const string_view& to be simply by-
value string_view. A string_view is only two words; it rarely ever makes
sense to pass one by reference if it’s not going to be mutated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants