Skip to content

clang-tidy error around std::string& member #65

Description

@springmeyer

While enabling clang-tidy support (#63 and #64) this error came up:

../src/object_async/hello_async.cpp:210:5: error: const string& members are dangerous; it is much better to use alternatives, such as pointers or simple constants [google-runtime-member-string-references,-warnings-as-errors]
    std::string const& name_;
    ^

And I found: https://clang.llvm.org/extra/clang-tidy/checks/google-runtime-member-string-references.html

This is interesting/surprising. I've used const std::string & members before and gotten away clean, I think. The motivation here for @GretaCB and I was to ensure we did not need to copy this string when going into the threadpool. The name is owned by the HelloObjectAsync class here and is only temporarily neede by the the AsyncHelloWorker that takes the const reference and keeps it as a member here.

This warning indicates that member references are worst than a pointer, which would achieve the same purpose. So I'm going to look into using a pointer.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions