Skip to content
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

ICU-22920 Avoid "return by const value" antipattern #3343

Merged
merged 1 commit into from
Jan 30, 2025

Conversation

Quuxplusone
Copy link
Contributor

@Quuxplusone Quuxplusone commented Jan 24, 2025

Returning a const-qualified prvalue doesn't do anything useful, but it does turn an assignment such as v = rb.getLocale(); from a move-assignment into a copy-assignment (because it's forbidden to move-from a const value, even if it's a const prvalue). Each affected site was diagnosed mechanically by my fork of Clang. E.g.:

warning: 'const' type qualifier on return type is a bad idea [-Wqual-class-return-type]
  391 | const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
      | ^~~~~

Checklist

  • Required: Issue filed: ICU-22920
  • Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-1234 Fix xyz"
  • Issue accepted (done by Technical Committee after discussion)
  • Tests included, if applicable
  • API docs and/or User Guide docs changed or added, if applicable

Returning a const-qualified prvalue doesn't do anything useful, but it does
turn an assignment such as `v = rb.getLocale();` from a move-assignment
into a copy-assignment (because it's forbidden to move-from a const value,
even if it's a const prvalue). Each affected site was diagnosed mechanically
by my fork of Clang. E.g.:

    warning: 'const' type qualifier on return type is a bad idea [-Wqual-class-return-type]
      391 | const Locale ResourceBundle::getLocale(ULocDataLocaleType type, UErrorCode &status) const
          | ^~~~~
@markusicu markusicu merged commit fb64693 into unicode-org:main Jan 30, 2025
94 checks passed
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.

3 participants