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

Clang tidy bugprone unhandled self assignment #58263

Conversation

jbytheway
Copy link
Contributor

Summary

None

Purpose of change

More static analysis.

This check looks for suspicious assignment operators that might not correctly handle self-assignment. In practice it is a bit prone to false-positives, but we have so few assignment operators in general that's not a big deal.

Describe the solution

Suppress these warnings in one place and fix them in another.

Also enable cert-oop54-cpp which is essentially the same check. Tweak its configuration so that it doesn't have more false positives.

Since this check made me look at the JsonArray assignment operator I noticed that its code was largely duplicated with the copy constructor and I eliminated that duplication.

Describe alternatives you've considered

The 'fix' to safe_reference's assignment operator is debatable. I can't think of a situation where it matters one way or the other.

I seriously considered just deciding against using these checks entirely.

Testing

Run clang-tidy.

Additional context

jbytheway added 2 commits June 7, 2022 19:53
This check looks for suspicious assignment operators that might not
correctly handle self-assignment.  In practice it is a bit prone to
false-positives, but we have so few assignment operators in general
that's not a big deal.

Also enable cert-oop54-cpp which is essentially the same check.  Tweak
its configuration so that it doesn't have more false positives.

Suppress these warnings in one place and fix them in another.
Implement it in terms of its assignment operator to reduce code
duplication.
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Jun 8, 2022
@dseguin dseguin merged commit 7b484ba into CleverRaven:master Jun 9, 2022
@jbytheway jbytheway deleted the clang-tidy_bugprone-unhandled-self-assignment branch June 11, 2022 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` json-styled JSON lint passed, label assigned by github actions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants