| 1 |
.. title:: clang-tidy - readability-redundant-string-init |
| 2 |
|
| 3 |
readability-redundant-string-init |
| 4 |
================================= |
| 5 |
|
| 6 |
Finds unnecessary string initializations. |
| 7 |
|
| 8 |
Examples |
| 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 |
|
| 31 |
Options |
| 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. |