xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/redundant-string-init.rst (revision 6e566bc5523f743bc34a7e26f050f1f2b4d699a8)
1.. title:: clang-tidy - readability-redundant-string-init
2
3readability-redundant-string-init
4=================================
5
6Finds unnecessary string initializations.
7
8Examples
9--------
10
11.. code-block:: c++
12
13  // Initializing string with empty string literal is unnecessary.
14  std::string a = "";
15  std::string b("");
16
17  // becomes
18
19  std::string a;
20  std::string b;
21
22  // Initializing a string_view with an empty string literal produces an
23  // instance that compares equal to string_view().
24  std::string_view a = "";
25  std::string_view b("");
26
27  // becomes
28  std::string_view a;
29  std::string_view b;
30
31Options
32-------
33
34.. option:: StringNames
35
36    Default is `::std::basic_string;::std::basic_string_view`.
37
38    Semicolon-delimited list of class names to apply this check to.
39    By default `::std::basic_string` applies to ``std::string`` and
40    ``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
41    to perform this check on custom classes.
42