summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Fixed crash 44745 in readability-else-after-returnNathan James2020-02-031-0/+4
| | | | | | | | | | | | | | | | Summary: Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=44745 | readability-else-after-return crashes ]] Reviewers: aaron.ballman, alexfh, hokein, JonasToth, gribozavr2 Reviewed By: alexfh Subscribers: merge_guards_bot, xazax.hun, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D73841 (cherry picked from commit d591bdce6d623208d4aeb335a762d839f0f8f0f7)
* [clang-tidy] Disable Checks on If constexpr statements in template ↵Nathan2020-01-231-1/+4
| | | | | | | | | | | | | | | | | | Instantiations for BugproneBranchClone and ReadabilityBracesAroundStatements Summary: fixes [[ https://bugs.llvm.org/show_bug.cgi?id=32203 | readability-braces-around-statements broken for if constexpr]] and [[ https://bugs.llvm.org/show_bug.cgi?id=44229 | bugprone-branch-clone false positive with template functions and constexpr ]] by disabling the relevant checks on if constexpr statements while inside an instantiated template. This is due to how the else branch of an if constexpr statement is folded away to a null statement if the condition evaluates to false Reviewers: alexfh, hokein, aaron.ballman, xazax.hun Reviewed By: aaron.ballman, xazax.hun Subscribers: rnkovacs, JonasToth, Jim, lebedev.ri, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D71980 (cherry picked from commit f9c46229e4ac29053747c96e08c574c6c48d544b)
* Added readability-qualified-auto checkNathan James2020-01-144-0/+334
| | | | | | | | Adds a check that detects any auto variables that are deduced to a pointer or a const pointer then adds in the const and asterisk according. Will also check auto L value references that could be written as const. This relates to the coding standard https://llvm.org/docs/CodingStandards.html#beware-unnecessary-copies-with-auto
* Fix readability-identifier-naming missing member variablesNathan James2020-01-131-6/+26
| | | | | Fixes PR41122 (missing fixes for member variables in a destructor) and PR29005 (does not rename class members in all locations).
* [APFloat] Fix checked error assert failuresEhud Katz2020-01-091-6/+8
| | | | | | | | | | | `APFLoat::convertFromString` returns `Expected` result, which must be "checked" if the LLVM_ENABLE_ABI_BREAKING_CHECKS preprocessor flag is set. To mark an `Expected` result as "checked" we must consume the `Error` within. In many cases, we are only interested in knowing if an error occured, without the need to examine the error info. This is achieved, easily, with the `errorToBool()` API.
* [clang-tidy] Disable match on `if constexpr` statements in template ↵Andi-Bogdan Postelnicu2020-01-081-1/+5
| | | | | | | | | | | | | | instantiation for `readability-misleading-indentation` check. Summary: Fixes fixes `readability-misleading-identation` for `if constexpr`. This is very similar to D71980. Reviewers: alexfh Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D72333
* [APFloat] Fix compilation warningsEhud Katz2020-01-061-2/+6
|
* NFC: Fix trivial typos in commentsKazuaki Ishizaki2020-01-042-2/+2
|
* Handle init statements in readability-else-after-returnNathan James2020-01-022-30/+216
| | | | | | | | | | Adds a new ASTMatcher condition called 'hasInitStatement()' that matches if, switch and range-for statements with an initializer. Reworked clang-tidy readability-else-after-return to handle variables in the if condition or init statements in c++17 ifs. Also checks if removing the else would affect object lifetimes in the else branch. Fixes PR44364.
* [NFC] Fixes -Wrange-loop-analysis warningsMark de Wever2020-01-011-1/+1
| | | | | | This avoids new warnings due to D68912 adds -Wrange-loop-analysis to -Wall. Differential Revision: https://reviews.llvm.org/D71857
* Fix readability-const-return-type identifying the wrong `const` tokenIlya Mirsky2019-12-241-2/+2
| | | | | | | Replace tidy::utils::lexer::getConstQualifyingToken with a corrected and also generalized to other qualifiers variant - getQualifyingToken. Fixes PR44326
* Fix false positive in magic number checker.Florin Iucha2019-12-241-3/+15
| | | | | cppcoreguidelines-avoid-magic-numbers should not warn about enum class. Fixes PR40640.
* [clang-tidy] Use early returns to make the code easier to read and ↵Alexander Kornienko2019-12-121-6/+5
| | | | potentially run faster
* Magic number checker shouldn't warn on user defined string literalsTibor Brunner2019-12-091-4/+15
| | | | Fixes a false positive brought up by PR40633.
* Optionally exclude bitfield definitions from magic numbers checkFlorin Iucha2019-12-072-8/+39
| | | | Adds the IgnoreBitFieldsWidths option to readability-magic-numbers.
* [clang-tidy] Fix PR26274Alexander Kornienko2019-12-061-64/+70
| | | | | | | | | | | | | | | | | Summary: This commit fixes http://llvm.org/PR26274 in a simpler and more correct way than 4736d63f752f8d13f4c6a9afd558565c32119718 did. See https://reviews.llvm.org/D69855#1767089 for details. Reviewers: gribozavr, aaron.ballman, gribozavr2 Reviewed By: aaron.ballman, gribozavr2 Subscribers: gribozavr2, merge_guards_bot, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70974
* Revert "Fix llvm-namespace-comment for macro expansions"Alexander Kornienko2019-12-032-135/+13
| | | | | This reverts commit 4736d63f752f8d13f4c6a9afd558565c32119718. This commit introduces a ton of false positives and incorrect fixes. See https://reviews.llvm.org/D69855#1767089 for details.
* Fix llvm-namespace-comment for macro expansionsMarcin Twardak2019-11-232-13/+135
| | | | | If a namespace is a macro name, it should be allowed to close the namespace with the same name.
* [NFC] Refactor representation of materialized temporariesTyker2019-11-191-1/+1
| | | | | | | | | | | | | | | Summary: this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718 Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: thakis, sammccall, ilya-biryukov, rnkovacs, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69360
* [clang-tidy] Give readability-redundant-member-init an option ↵Mitchell Balan2019-11-192-6/+24
| | | | | | | | | | | | | | | | | | | IgnoreBaseInCopyConstructors to avoid breaking code with gcc -Werror=extra Summary: readability-redundant-member-init removes redundant / unnecessary member and base class initialization. Unfortunately for the specific case of a copy constructor's initialization of a base class, gcc at strict warning levels warns if "base class is not initialized in the copy constructor of a derived class". This patch adds an option `IgnoreBaseInCopyConstructors` defaulting to 0 (thus maintaining current behavior by default) to skip the specific case of removal of redundant base class initialization in the copy constructor. Enabling this option enables the resulting code to continue to compile successfully under `gcc -Werror=extra`. New test cases `WithCopyConstructor1` and `WithCopyConstructor2` in clang-tools-extra/test/clang-tidy/readability-redundant-member-init.cpp show that it removes redundant members even from copy constructors. Reviewers: malcolm.parsons, alexfh, hokein, aaron.ballman, lebedev.ri Patch by: poelmanc Subscribers: mgehre, lebedev.ri, cfe-commits Tags: #clang, #clang-tools-extra Differential revision: https://reviews.llvm.org/D69145
* [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.
* Revert "[NFC] Refactor representation of materialized temporaries"Nico Weber2019-11-171-1/+1
| | | | | | This reverts commit 08ea1ee2db5f9d6460fef1d79d0d1d1a5eb78982. It broke ./ClangdTests/FindExplicitReferencesTest.All on the bots, see comments on https://reviews.llvm.org/D69360
* [NFC] Refactor representation of materialized temporariesTyker2019-11-161-1/+1
| | | | | | | | | | | | | | | Summary: this patch refactor representation of materialized temporaries to prevent an issue raised by rsmith in https://reviews.llvm.org/D63640#inline-612718 Reviewers: rsmith, martong, shafik Reviewed By: rsmith Subscribers: rnkovacs, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D69360
* [clang-tidy] Give readability-redundant-string-init a customizable list of ↵Mitchell Balan2019-11-152-11/+41
| | | | | | | | | | | | | | | | | | | 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-152-41/+11
| | | | | | list of string types to fix" This reverts commit 96fbc32cb9ea23b1e7e3ff6906ec3ccda9500982.
* [clang-tidy] Give readability-redundant-string-init a customizable list of ↵Mitchell Balan2019-11-152-11/+41
| | | | | | | | | | | | | | | | | 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
* [clang-tidy] Add readability-make-member-function-constMatthias Gehre2019-11-064-0/+302
| | | | | | | | | | | | | | | | | | Summary: Finds non-static member functions that can be made ``const`` because the functions don't use ``this`` in a non-const way. The check conservatively tries to preserve logical costness in favor of physical costness. See readability-make-member-function-const.rst for more details. Reviewers: aaron.ballman, gribozavr, hokein, alexfh Subscribers: mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68074
* Fix readability-identifier-naming to prevent variables becoming keywords.Daniel2019-10-302-22/+68
| | | | | Do not provide a fix-it when clang-tidy encounters a name that would become a keyword.
* Add the readability-redundant-access-specifiers check.Aaron Ballman2019-10-304-0/+128
| | | | | | This finds redundant access specifier declarations inside classes, structs, and unions. Patch by Mateusz Mackowski.
* Use std::unique_ptr in ClangTidyCheckFactoriesDmitri Gribenko2019-09-262-0/+3
| | | | | | | I had to explicitly define some destructors that could only be defined in the corresponding .cpp files. llvm-svn: 372978
* [clang-tidy] readability-identifier-naming shouldn't complain about CRTP ↵Sam McCall2019-08-281-0/+10
| | | | | | | | | | | | | | pseudo-overrides Reviewers: ilya-biryukov Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66864 llvm-svn: 370193
* Remove \brief commands from doxygen comments.Dmitri Gribenko2019-08-225-7/+7
| | | | | | | | | | | | | | | | | | | | | | | Summary: We've been running doxygen with the autobrief option for a couple of years now. This makes the \brief markers into our comments redundant. Since they are a visual distraction and we don't want to encourage more \brief markers in new code either, this patch removes them all. Patch produced by for i in $(git grep -l '\\brief'); do perl -pi -e 's/\\brief //g' $i & done [This is analogous to LLVM r331272 and CFE r331834] Subscribers: srhines, nemanjai, javed.absar, kbarton, MaskRay, jkorous, arphaman, jfb, kadircet, jsji, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D66578 llvm-svn: 369643
* [clang-tools-extra] Migrate llvm::make_unique to std::make_uniqueJonas Devlieghere2019-08-142-2/+2
| | | | | | | | | | Now that we've moved to C++14, we no longer need the llvm::make_unique implementation from STLExtras.h. This patch is a mechanical replacement of (hopefully) all the llvm::make_unique instances across the monorepo. Differential revision: https://reviews.llvm.org/D66259 llvm-svn: 368944
* [clang-tidy] Adjust location of namespace comment diagnosticIlya Biryukov2019-07-171-1/+8
| | | | | | | | | | | | | | | | | | | | | | Summary: If there is no comment, place it at the closing brace of a namespace definition. Previously it was placed at the next character after the closing brace. The new position produces a better location for highlighting in clangd and does not seem to make matters worse for clang-tidy. Reviewers: alexfh, hokein Reviewed By: alexfh, hokein Subscribers: xazax.hun, kadircet, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D64861 llvm-svn: 366337
* [clang-tidy] initial version of readability-convert-member-functions-to-staticMatthias Gehre2019-07-164-0/+213
| | | | | | | | | | | | | | | | | | | | | | | | Summary: Finds non-static member functions that can be made ``static``. I have run this check (repeatedly) over llvm-project. It made 1708 member functions ``static``. Out of those, I had to exclude 22 via ``NOLINT`` because their address was taken and stored in a variable of pointer-to-member type (e.g. passed to llvm::StringSwitch). It also made 243 member functions ``const``. (This is currently very conservative to have no false-positives and can hopefully be extended in the future.) You can find the results here: https://github.com/mgehre/llvm-project/commits/static_const_eval Reviewers: alexfh, aaron.ballman Subscribers: mgorny, xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61749 llvm-svn: 366265
* [clang-tidy] Fix null pointer dereference in readability-identifier-namingHaojian Wu2019-05-281-4/+5
| | | | | | | | | | | | | | | | | | | | | | | | Summary: readability-identifier-naming causes a null pointer dereference when checking an identifier introduced by a structured binding whose right hand side is an undeclared identifier. Running the check on a file that is just the following results in a crash: ``` auto [left] = right; ``` Patch by Mark Stegeman! Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: hokein, aaron.ballman Subscribers: madsravn, xazax.hun, cfe-commits Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D62404 llvm-svn: 361809
* DeleteNullPointerCheck now deletes until the end brace of the condition.Mads Ravn2019-05-261-3/+6
| | | | | | | | Patch by Jonathan Camilleri Differential Revision https://reviews.llvm.org/D61861 llvm-svn: 361735
* [clang-tidy] Handle member variables in readability-simplify-boolean-exprJonas Toth2019-05-161-18/+17
| | | | | | | | | | | | | | | | | - Add readability-simplify-boolean-expr test cases for member variables Fixes PR40179 Patch by LegalizeAdulthood. Reviewers: alexfh, hokein, aaron.ballman, JonasToth Reviewed By: JonasToth Subscribers: jdoerfert, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D56323 llvm-svn: 360882
* [clang-tidy] Fix invalid fixit for ↵Matthias Gehre2019-05-141-0/+1
| | | | | | | | | | | | | | | | | | | readability-static-accessed-through-instance (bug 40544) Summary: Fixed https://bugs.llvm.org/show_bug.cgi?id=40544 Before, we would generate a fixit like `(anonymous namespace)::Foo::fun();` for the added test case. Reviewers: aaron.ballman, alexfh, xazax.hun Subscribers: rnkovacs, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D61874 llvm-svn: 360698
* [clang-tidy] readability-redundant-declaration: fix false positive with C ↵Matthias Gehre2019-05-131-2/+8
| | | | | | | | | | | | | | | | | | | "extern inline" Summary: readability-redundant-declaration was diagnosing a redundant declaration on "extern inline void f();", which is needed in C code to force an external definition of the inline function f. (This is different to how inline behaves in C++). Reviewers: alexfh, danielmarjamaki Subscribers: xazax.hun, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D61700 llvm-svn: 360613
* Fixed: Duck-typing in readability-redundant-smartptr-get didn't catch MSVC ↵Florian Gross2019-05-021-13/+16
| | | | | | | | STL smart pointers. Differential Revision: https://reviews.llvm.org/D61209 llvm-svn: 359801
* Re-apply r357823 "[Lexer] NFC: Fix an off-by-one bug in getAsCharRange()."Artem Dergachev2019-04-231-1/+4
| | | | | | | | | It now comes with a follow-up fix for the clients of this API in clangd and clang-tidy. Differential Revision: https://reviews.llvm.org/D59977 llvm-svn: 359035
* [clang-tidy] Fix invalid location in readability-misleading-indentation ↵Alexander Kornienko2019-04-171-1/+5
| | | | | | | | | | diagnostic Before this patch readability-misleading-indentation could issue diagnostics with an invalid location, which would lead to an assertion failure in ClangTidyContext::diag() llvm-svn: 358589
* [clang-tidy] Switch checks to #include "ClangTidyCheck.h"Alexander Kornienko2019-03-2533-33/+33
| | | | llvm-svn: 356892
* [clang-tidy] Move all checks to the new registerPPCallbacks APIAlexander Kornienko2019-03-222-5/+5
| | | | llvm-svn: 356796
* [clang-tidy] Expand modular headers for PPCallbacksAlexander Kornienko2019-03-222-5/+7
| | | | | | | | | | | | | | | | | | | | | | Summary: Add a way to expand modular headers for PPCallbacks. Checks can opt-in for this expansion by overriding the new registerPPCallbacks virtual method and registering their PPCallbacks in the preprocessor created for this specific purpose. Use module expansion in the readability-identifier-naming check Reviewers: gribozavr, usaxena95, sammccall Reviewed By: gribozavr Subscribers: nemanjai, mgorny, xazax.hun, kbarton, jdoerfert, cfe-commits Tags: #clang, #clang-tools-extra Differential Revision: https://reviews.llvm.org/D59528 llvm-svn: 356750
* Fix file headers. NFCFangrui Song2019-03-013-3/+3
| | | | llvm-svn: 355188
* [clang-tidy][NFC] Fix typo.Yitzhak Mandelbaum2019-02-081-1/+1
| | | | | | Fix placement of comma from previous (test) commit. llvm-svn: 353525
OpenPOWER on IntegriCloud