Conversation
|
I believe it is best practice to prefer reference instead of pointer;
Imho, not if the intention is that it should still reference the same global object. We want that "files" point at the same object.
but just changing from reference to pointer does not solve that issue |
I agree that references are preferable for public interfaces or trivial classes when possible, however semantically sensible copy and move assignments aren't really possible with non-trivial classes that contain references. References are still used in public-facing functions, only the internals are changed.
If we really want to have exactly one global
The bugs I'm referring to are on line 513, 529 and 1512 in simplecpp.cpp. It seems pretty clear to me that intent is to rebind the references, which is the behavior one would expect from an assignment operation, but that behavior is only possible with pointers. It's not needed for all classes though, |
|
Maybe this should be approached from the other end by resolving #424 first. |
|
I started removing the need for the references from the inside out. I will post the first in series of several PRs soon. |
|
I posted the first one with #569. |
Having references as class members complicates copy/move constructors and assignment operators and in some cases prevents them from being defaulted. They are also a source of bugs, as there are currently several instances of copy/move operators assigning to their referred object where the intended behavior most likely is to rebind them. This PR replaces most reference members with pointers, and makes explicit some of the semantics of affected classes with an explicitly deleted/defaulted copy/move assignment constructor/operator.
Fixes clang-tidy issues in #421.