2016-02-26 07:57:23 +08:00
|
|
|
.. title:: clang-tidy - readability-redundant-string-init
|
|
|
|
|
|
|
|
readability-redundant-string-init
|
|
|
|
=================================
|
|
|
|
|
|
|
|
Finds unnecessary string initializations.
|
|
|
|
|
[clang-tidy] Give readability-redundant-string-init a customizable list of string types to fix
Summary:
This patch adds a feature requested in https://reviews.llvm.org/D69238 to enable `readability-redundant-string-init` to take a list of strings to apply the fix to rather than hard-coding `basic_string`. It adds a `StringNames` option of semicolon-delimited names of string classes to which to apply this fix. Tests ensure this works with test class out::TestString as well as std::string and std::wstring as before. It should be applicable to llvm::StringRef, QString, etc.
Note: This commit was previously reverted due to a failing unit test. That test has been fixed in this version.
Reviewers: MyDeveloperDay, aaron.ballman, hokein, alexfh, JonasToth, gribozavr2
Patch by: poelmanc
Subscribers: gribozavr2, xazax.hun, Eugene.Zelenko, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D69548
2019-11-16 07:09:27 +08:00
|
|
|
Examples
|
|
|
|
--------
|
2016-02-26 07:57:23 +08:00
|
|
|
|
2016-08-27 01:46:51 +08:00
|
|
|
.. code-block:: c++
|
2016-02-26 07:57:23 +08:00
|
|
|
|
|
|
|
// Initializing string with empty string literal is unnecessary.
|
|
|
|
std::string a = "";
|
|
|
|
std::string b("");
|
2017-04-11 15:10:48 +08:00
|
|
|
|
|
|
|
// becomes
|
|
|
|
|
|
|
|
std::string a;
|
|
|
|
std::string b;
|
[clang-tidy] Give readability-redundant-string-init a customizable list of string types to fix
Summary:
This patch adds a feature requested in https://reviews.llvm.org/D69238 to enable `readability-redundant-string-init` to take a list of strings to apply the fix to rather than hard-coding `basic_string`. It adds a `StringNames` option of semicolon-delimited names of string classes to which to apply this fix. Tests ensure this works with test class out::TestString as well as std::string and std::wstring as before. It should be applicable to llvm::StringRef, QString, etc.
Note: This commit was previously reverted due to a failing unit test. That test has been fixed in this version.
Reviewers: MyDeveloperDay, aaron.ballman, hokein, alexfh, JonasToth, gribozavr2
Patch by: poelmanc
Subscribers: gribozavr2, xazax.hun, Eugene.Zelenko, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D69548
2019-11-16 07:09:27 +08:00
|
|
|
|
2020-11-08 03:14:08 +08:00
|
|
|
// Initializing a string_view with an empty string literal produces an
|
|
|
|
// instance that compares equal to string_view().
|
|
|
|
std::string_view a = "";
|
|
|
|
std::string_view b("");
|
|
|
|
|
|
|
|
// becomes
|
|
|
|
std::string_view a;
|
|
|
|
std::string_view b;
|
|
|
|
|
[clang-tidy] Give readability-redundant-string-init a customizable list of string types to fix
Summary:
This patch adds a feature requested in https://reviews.llvm.org/D69238 to enable `readability-redundant-string-init` to take a list of strings to apply the fix to rather than hard-coding `basic_string`. It adds a `StringNames` option of semicolon-delimited names of string classes to which to apply this fix. Tests ensure this works with test class out::TestString as well as std::string and std::wstring as before. It should be applicable to llvm::StringRef, QString, etc.
Note: This commit was previously reverted due to a failing unit test. That test has been fixed in this version.
Reviewers: MyDeveloperDay, aaron.ballman, hokein, alexfh, JonasToth, gribozavr2
Patch by: poelmanc
Subscribers: gribozavr2, xazax.hun, Eugene.Zelenko, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D69548
2019-11-16 07:09:27 +08:00
|
|
|
Options
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. option:: StringNames
|
|
|
|
|
2020-11-08 03:14:08 +08:00
|
|
|
Default is `::std::basic_string;::std::basic_string_view`.
|
[clang-tidy] Give readability-redundant-string-init a customizable list of string types to fix
Summary:
This patch adds a feature requested in https://reviews.llvm.org/D69238 to enable `readability-redundant-string-init` to take a list of strings to apply the fix to rather than hard-coding `basic_string`. It adds a `StringNames` option of semicolon-delimited names of string classes to which to apply this fix. Tests ensure this works with test class out::TestString as well as std::string and std::wstring as before. It should be applicable to llvm::StringRef, QString, etc.
Note: This commit was previously reverted due to a failing unit test. That test has been fixed in this version.
Reviewers: MyDeveloperDay, aaron.ballman, hokein, alexfh, JonasToth, gribozavr2
Patch by: poelmanc
Subscribers: gribozavr2, xazax.hun, Eugene.Zelenko, cfe-commits
Tags: #clang-tools-extra, #clang
Differential Revision: https://reviews.llvm.org/D69548
2019-11-16 07:09:27 +08:00
|
|
|
|
|
|
|
Semicolon-delimited list of class names to apply this check to.
|
|
|
|
By default `::std::basic_string` applies to ``std::string`` and
|
|
|
|
``std::wstring``. Set to e.g. `::std::basic_string;llvm::StringRef;QString`
|
|
|
|
to perform this check on custom classes.
|