summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/docs/clang-tidy/checks/google-runtime-member-string-references.rst
blob: 8e468e3b79fc9e630dd1aaadaf35b511947d8b0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
.. title:: clang-tidy - google-runtime-member-string-references

google-runtime-member-string-references
=======================================

Finds members of type ``const string&``.

const string reference members are generally considered unsafe as they can
be created from a temporary quite easily.

.. code:: c++

  struct S {
    S(const string &Str) : Str(Str) {}
    const string &Str;
  };
  S instance("string");

In the constructor call a string temporary is created from ``const char *``
and destroyed immediately after the call. This leaves around a dangling
reference.

This check emit warnings for both ``std::string`` and ``::string`` const
reference members.

Corresponding cpplint.py check name: `runtime/member_string_reference`.
OpenPOWER on IntegriCloud