Title: Make copy-constructible classes copyable by pfultz2 · Pull Request #8705 · cppcheck-opensource/cppcheck · GitHub
Open Graph Title: Make copy-constructible classes copyable by pfultz2 · Pull Request #8705 · cppcheck-opensource/cppcheck
X Title: Make copy-constructible classes copyable by pfultz2 · Pull Request #8705 · cppcheck-opensource/cppcheck
Description: Lots of copy constructible classes were using const and ref members which makes the classes non-copyable due to no longer supporting a copy-assignment. I replaced the ref members with a NonNullPtr class which is kind of a mix of gsl::non_null and std::reference_wrapper. This helps prevent assigning it as null since it only accepts a reference and not a pointer. Now this PR doesnt replace all reference members, just for the classes that are copy-constructible. If we want to convert a class back to use reference or const members then we can delete the copy constructor and assignment. Furthermore, I enabled the clang-tidy check cppcoreguidelines-avoid-const-or-ref-data-members to check for these cases in the future. Here are some references explaining why this is bad practice: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#rc-constref https://lesleylai.info/en/const-and-reference-member-variables/ https://quuxplusone.github.io/blog/2022/01/23/dont-const-all-the-things/#data-members-never-const Beyond just being bad practice, this also has prevent me from doing certain things with the ForwardAnalyzer recently that might have improved it further such as joining or swaping a forked analyzer. I intentionally made these classes copyable for this reason(and were changed to non-copyable against my feedback as well). I understand that using references help prevent dereferencing a nullptr which is why I added a NonNullPtr class instead of using raw pointers like previously.
Open Graph Description: Lots of copy constructible classes were using const and ref members which makes the classes non-copyable due to no longer supporting a copy-assignment. I replaced the ref members with a NonNullPtr ...
X Description: Lots of copy constructible classes were using const and ref members which makes the classes non-copyable due to no longer supporting a copy-assignment. I replaced the ref members with a NonNullPtr ...
Opengraph URL: https://github.com/cppcheck-opensource/cppcheck/pull/8705
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:a80a2503-4ab3-84f0-43a1-bc10a5bb1074 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9D6A:B5AA6:3488401:49ADE45:6A4F7FC0 |
| html-safe-nonce | 0dfdaab79c028060edd4bbe21eeef33bc86ae11d17493773cbf3f15bfceb0ac3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDZBOkI1QUE2OjM0ODg0MDE6NDlBREU0NTo2QTRGN0ZDMCIsInZpc2l0b3JfaWQiOiI1MTc1NDE1MzI5ODA3ODkyNDE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 035c40642615ae7603f0b767ebc870ad530407328783e3abb876c824e8374226 |
| hovercard-subject-tag | pull_request:4008493452 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/cppcheck-opensource/cppcheck/pull/8705/files |
| twitter:image | https://avatars.githubusercontent.com/u/1306044?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1306044?s=400&v=4 |
| og:image:alt | Lots of copy constructible classes were using const and ref members which makes the classes non-copyable due to no longer supporting a copy-assignment. I replaced the ref members with a NonNullPtr ... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b92d11c0aa4a77d54ef4af1078b6a15fb5a70a215b30c4ecf28889d5a8e656d9 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/cppcheck-opensource/cppcheck git https://github.com/cppcheck-opensource/cppcheck.git |
| octolytics-dimension-user_id | 278097703 |
| octolytics-dimension-user_login | cppcheck-opensource |
| octolytics-dimension-repository_id | 143131 |
| octolytics-dimension-repository_nwo | cppcheck-opensource/cppcheck |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 143131 |
| octolytics-dimension-repository_network_root_nwo | cppcheck-opensource/cppcheck |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 4b249b445842943ed31549e027f57a8ade9881ed |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width