◐ Shell
clean mode source ↗

Replace reference members with pointers by glankk · Pull Request #493 · cppcheck-opensource/simplecpp

I believe it is best practice to prefer reference instead of pointer; https://isocpp.org/wiki/faq/references#refs-vs-ptrs

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.

Imho, not if the intention is that it should still reference the same global object. We want that "files" point at the same object.

If we really want to have exactly one global files then I think the lesser evil would be to have a singleton.

but just changing from reference to pointer does not solve that issue

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, Location is an example of a trivial class where a reference could be preferred.