2015-12-23 01:36:49 +08:00
|
|
|
.. title:: clang-tidy - google-runtime-member-string-references
|
|
|
|
|
2015-08-28 02:10:07 +08:00
|
|
|
google-runtime-member-string-references
|
|
|
|
=======================================
|
|
|
|
|
|
|
|
Finds members of type ``const string&``.
|
|
|
|
|
2016-08-27 01:46:51 +08:00
|
|
|
const string reference members are generally considered unsafe as they can be
|
|
|
|
created from a temporary quite easily.
|
2015-08-28 02:10:07 +08:00
|
|
|
|
2016-08-27 01:46:51 +08:00
|
|
|
.. code-block:: c++
|
2015-08-28 02:10:07 +08:00
|
|
|
|
|
|
|
struct S {
|
|
|
|
S(const string &Str) : Str(Str) {}
|
|
|
|
const string &Str;
|
|
|
|
};
|
|
|
|
S instance("string");
|
|
|
|
|
2016-08-27 01:46:51 +08:00
|
|
|
In the constructor call a string temporary is created from ``const char *`` and
|
|
|
|
destroyed immediately after the call. This leaves around a dangling reference.
|
2015-08-28 02:10:07 +08:00
|
|
|
|
|
|
|
This check emit warnings for both ``std::string`` and ``::string`` const
|
|
|
|
reference members.
|
|
|
|
|
2016-04-02 09:07:18 +08:00
|
|
|
Corresponding cpplint.py check name: `runtime/member_string_reference`.
|