summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability/RedundantStringInitCheck.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Fix readability-redundant-string-init for c++17/c++2aMitchell Balan2019-11-191-6/+7
| | | | | | | | | | | | | | | | | | | Summary: `readability-redundant-string-init` was one of several clang-tidy checks documented as failing for C++17. (The failure mode in C++17 is that it changes `std::string Name = ""`; to `std::string Name = Name;`, which actually compiles but crashes at run-time.) Analyzing the AST with `clang -Xclang -ast-dump` showed that the outer `CXXConstructExprs` that previously held the correct SourceRange were being elided in C++17/2a, but the containing `VarDecl` expressions still had all the relevant information. So this patch changes the fix to get its source ranges from `VarDecl`. It adds one test `std::string g = "u", h = "", i = "uuu", j = "", k;` to confirm proper warnings and fixit replacements in a single `DeclStmt` where some strings require replacement and others don't. The readability-redundant-string-init.cpp and readability-redundant-string-init-msvc.cpp tests now pass for C++11/14/17/2a. Reviewers: gribozavr, etienneb, alexfh, hokein, aaron.ballman, gribozavr2 Patch by: poelmanc Subscribers: NoQ, MyDeveloperDay, Eugene.Zelenko, dylanmckay, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D69238
* Revert "[clang-tidy] modernize-use-override new option AllowOverrideAndFinal"Mitchell Balan2019-11-191-7/+6
| | | | This reverts commit 50e99563fb0459f5160572eef3c4e6062b8ad3f2.
* [clang-tidy] Give readability-redundant-string-init a customizable list of ↵Mitchell Balan2019-11-151-9/+34
| | | | | | | | | | | | | | | | | | | 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
* Revert "[clang-tidy] Give readability-redundant-string-init a customizable ↵Mitchell Balan2019-11-151-34/+9
| | | | | | list of string types to fix" This reverts commit 96fbc32cb9ea23b1e7e3ff6906ec3ccda9500982.
* [clang-tidy] Give readability-redundant-string-init a customizable list of ↵Mitchell Balan2019-11-151-9/+34
| | | | | | | | | | | | | | | | | 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. 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
* [clang-tidy] modernize-use-override new option AllowOverrideAndFinalMitchell Balan2019-11-151-13/+13
| | | | | | | | | | | | | | | | | | | Summary: In addition to adding `override` wherever possible, clang-tidy's `modernize-use-override` nicely removes `virtual` when `override` or `final` is specified, and further removes override when final is specified. While this is great default behavior, when code needs to be compiled with gcc at high warning levels that include `gcc -Wsuggest-override` or `gcc -Werror=suggest-override`, clang-tidy's removal of the redundant `override` keyword causes gcc to emit a warning or error. This discrepancy / conflict has been noted by others including a comment on Stack Overflow and by Mozilla's Firefox developers. This patch adds an AllowOverrideAndFinal option defaulting to 0 - thus preserving current behavior - that when enabled allows both `override` and `final` to co-exist, while still fixing all other issues. The patch includes a test file verifying all combinations of virtual/override/final, and mentions the new option in the release notes. Reviewers: alexfh, djasper, JonasToth Patch by: poelmanc Subscribers: JonasToth, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70165
* Update the file headers across all of the LLVM projects in the monorepoChandler Carruth2019-01-191-4/+3
| | | | | | | | | | | | | | | | | to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
* Adapt clang-tidy checks to changing semantics of hasDeclaration.Manuel Klimek2017-08-021-1/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D36154 llvm-svn: 309810
* [clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang2016-11-081-4/+3
| | | | | | | | | | | | | | | | Summary: Ran clang-format on all .c/.cpp/.h files in clang-tools-extra. Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories. Reviewers: klimek, alexfh Subscribers: nemanjai Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26329 llvm-svn: 286221
* Fix clang-tidy patterns to adapt to newly added ExprWithCleanups nodes.Tim Shen2016-06-211-9/+9
| | | | | | | | | | | | Summary: This is a fix for the new ExprWithCleanups introduced by clang's temporary variable lifetime marks change. Reviewers: bkramer, sbenza, angelgarcia, alexth Subscribers: rsmith, cfe-commits Differential Revision: http://reviews.llvm.org/D21243 llvm-svn: 273310
* [clang-tidy] Lift common matchers to utils namespaceEtienne Bergeron2016-05-171-12/+3
| | | | | | | | | | | | | | Summary: This patch is lifting matchers used by more than one checkers to the common namespace. Reviewers: aaron.ballman, alexfh Subscribers: aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D19841 llvm-svn: 269804
* [clang-tidy] Fix FP with readability-redundant-string-init for default argumentsEtienne Bergeron2016-04-071-1/+2
| | | | | | | | | | | | | | | | | | | | | | Summary: Clang-tidy is reporting a warning of redundant string initialisation on a string parameter initialized with empty string. See bug: 27087 The reported example is: ``` #include <string> void fn(std::string a = ""); ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18829 llvm-svn: 265671
* [clang-tidy] Fix redundant-string-init check with msvc 14 headers.Etienne Bergeron2016-03-221-15/+32
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The string constructors are not defined using optional parameters and are not recognized by the redundant-string-init checker. The following patch fixes the redundant-string-init checker for the Visual Studio 14 headers file. The matcher now accept both variant (with 1 and 2 parameters). Also added new unittests. Similar issue than: [[ http://reviews.llvm.org/D18285 | review ]] In the xstring.h header, the constructors are defined this way: ``` basic_string(const _Myt& _Right) [...] basic_string(const _Myt& _Right, const _Alloc& _Al) [...] ``` Reviewers: alexfh, hokein Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18293 llvm-svn: 264069
* Add a new check, readability-redundant-string-init, that checks unnecessary ↵Alexander Kornienko2016-02-251-0/+62
string initializations. Reviewers: hokein, alexfh Subscribers: cfe-commits Patch by Shuai Wang! Differential Revision: http://reviews.llvm.org/D17586 llvm-svn: 261939
OpenPOWER on IntegriCloud