summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize
Commit message (Collapse)AuthorAgeFilesLines
...
* [clang-tidy] Fix another crash in make-unique check.Haojian Wu2017-08-091-0/+7
| | | | | | | | | | | | | | | | | Summary: The crash happens when calling `reset` method without any preceding operation like "->" or ".", this could happen in a subclass of the "std::unique_ptr". Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36452 llvm-svn: 310496
* [clang-tidy] Ignore macros in make-unique check.Haojian Wu2017-08-042-2/+27
| | | | | | | | | | | | | | | | Summary: The check doesn't fully support smart-ptr usages inside macros, which may cause incorrect fixes, or even crashes, ignore them for now. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36264 llvm-svn: 310050
* [clang-tidy] Support initializer-list constructor cases in ↵Haojian Wu2017-08-041-10/+27
| | | | | | | | | | | | | | modernize-make-unique. Reviewers: alexfh Reviewed By: alexfh Subscribers: malcolm.parsons, JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D36016 llvm-svn: 310035
* Adapt clang-tidy checks to changing semantics of hasDeclaration.Manuel Klimek2017-08-023-36/+40
| | | | | | Differential Revision: https://reviews.llvm.org/D36154 llvm-svn: 309810
* [clang-tidy] Handle anonymous structs/unions in member init checks.Malcolm Parsons2017-08-011-10/+11
| | | | | | | | | | | | Use getAnyMember() instead of getMember() to avoid crash on anonymous structs/unions. Don't warn about initializing members of an anonymous union. Fixes PR32966. Reviewed by alexfh. llvm-svn: 309668
* [clang-tidy] s/1/true/, NFCAlexander Kornienko2017-07-201-1/+1
| | | | llvm-svn: 308621
* [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are usedAlexander Kornienko2017-07-204-4/+4
| | | | llvm-svn: 308605
* [clang-tidy] Add modernize-use-bool-literals.IgnoreMacros optionAlexander Kornienko2017-07-172-3/+15
| | | | llvm-svn: 308181
* [clang-tidy] Add new modernize use unary assert checkGabor Horvath2017-07-124-0/+85
| | | | | | | | Patch by: Lilla Barancsuk Differential Revision: https://reviews.llvm.org/D35257 llvm-svn: 307791
* [clang-tidy] Fix modernize-use-override incorrect replacementAlexander Kornienko2017-07-071-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: For the following code: `modernize-use-override` generates a replacement with incorrect location. ``` struct IntPair { int first, second; }; struct A { virtual void il(IntPair); }; struct B : A { void il(IntPair p = {1, (2 + 3)}) {}; // Generated Fixit: void il(IntPair p = override {1, (2 + 3)}) {}; // Should be: void il(IntPair p = {1, (2 + 3)}) override {}; }; ``` This fixes that and adds a unit test. Reviewers: alexfh, aaron.ballman, hokein Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Tags: #clang-tools-extra Patch by Victor Gao! Differential Revision: https://reviews.llvm.org/D35078 llvm-svn: 307379
* [clang-tidy] Add "MakeSmartPtrFunction" option to ↵Haojian Wu2017-07-052-8/+54
| | | | | | | | | | | | | | modernize-make-shared/unique checks. Reviewers: alexfh, aaron.ballman Reviewed By: alexfh Subscribers: JDevlieghere, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34206 llvm-svn: 307130
* [clang-tidy] Fix modernize-use-nullptr only warns the first NULL argument.Haojian Wu2017-06-291-1/+1
| | | | | | | | | | | | Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34526 llvm-svn: 306651
* [clang-tidy] Handle new array expressions in modernize-make-unique check.Haojian Wu2017-06-272-14/+45
| | | | | | | | | | | | Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34674 llvm-svn: 306421
* [clang-tidy] Fix type names in modernize-use-unique/shared_ptr checks.Haojian Wu2017-06-271-3/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: If the class being created in unique_ptr is in anonymous nampespace, the anonymous namespace will be included in the apply-fixes. This patch fix this. ``` namespace { class Foo {}; } std::unique_ptr<Foo> f; f.reset(new Foo()); // Before the change: f = std::make_unique<(annonymous namespace)::Foo>(); // After the change: f = std::make_unique<Foo>(); ``` Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, xazax.hun, cfe-commits Differential Revision: https://reviews.llvm.org/D34286 llvm-svn: 306378
* [clang-tidy] Fix a false positive in modernize-use-nullptr.Haojian Wu2017-06-231-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | Summary: The FP happens when a casting nullptr expression is used within a NULL-default-arguemnt cxx constructor. Before the fix, the check will give a warning on nullptr when running with the test case, which should not happen: ``` G(g(static_cast<char*>(nullptr))); ^~~~~~~~~~~ nullptr ``` Reviewers: alexfh Reviewed By: alexfh Subscribers: cfe-commits, xazax.hun Differential Revision: https://reviews.llvm.org/D34524 llvm-svn: 306091
* Wdocumentation fix.Simon Pilgrim2017-06-081-1/+1
| | | | llvm-svn: 304988
* [clang-tidy] New checker to replace dynamic exception specificationsAlexander Kornienko2017-06-084-0/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: New checker to replace dynamic exception specifications This is an alternative to D18575 which relied on reparsing the decl to find the location of dynamic exception specifications, but couldn't deal with preprocessor conditionals correctly without reparsing the entire file. This approach uses D20428 to find dynamic exception specification locations and handles all cases correctly. Reviewers: aaron.ballman, alexfh Reviewed By: aaron.ballman, alexfh Subscribers: xazax.hun, mgehre, malcolm.parsons, mgorny, JDevlieghere, cfe-commits, Eugene.Zelenko, etienneb Patch by Don Hinton! Differential Revision: https://reviews.llvm.org/D20693 llvm-svn: 304977
* [clang-tidy] Replace matchesName with hasName where no regex is neededAlexander Kornienko2017-05-172-9/+9
| | | | llvm-svn: 303263
* [clang-tidy] A bit of refactoring of modernize-replace-auto-ptr. NFCAlexander Kornienko2017-05-171-141/+69
| | | | llvm-svn: 303256
* [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple callsJakub Kuderski2017-05-162-18/+33
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled. Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`. Eq. ``` std::vector<std::tuple<int, char, bool>> v; v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true); ``` Reviewers: alexfh, aaron.ballman, Prazek, hokein Reviewed By: Prazek Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32690 llvm-svn: 303145
* Revert "[clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls"Jakub Kuderski2017-05-162-33/+18
| | | | | | This reverts commit r303139. The commit made docs build emit a warning. llvm-svn: 303140
* [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple callsJakub Kuderski2017-05-162-18/+33
| | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch makes modernize-use-emplace remove unnecessary make_ calls from push_back calls and turn them into emplace_back -- the same way make_pair calls are handled. Custom make_ calls can be removed for custom tuple-like types -- two new options that control that are `TupleTypes` and `TupleMakeFunctions`. By default, the check removes calls to `std::make_pair` and `std::make_tuple`. Eq. ``` std::vector<std::tuple<int, char, bool>> v; v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', true); ``` Reviewers: alexfh, aaron.ballman, Prazek, hokein Reviewed By: Prazek Subscribers: JDevlieghere, xazax.hun, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32690 llvm-svn: 303139
* clang-tidy: add IgnoreMacros option to modernize-use-default-member-initMiklos Vajna2017-05-083-2/+9
| | | | | | | | | | | | | | | | | | | Summary: And also enable it by default to be consistent with e.g. modernize-use-using. This helps e.g. when running this check on cppunit client code where the macro is provided by the system, so there is no easy way to modify it. Reviewers: alexfh, malcolm.parsons Reviewed By: malcolm.parsons Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D32945 llvm-svn: 302429
* [clang-tidy] Ignore private =deleted methods in macros.Alexander Kornienko2017-05-081-2/+7
| | | | | | | | modernize-use-equals-delete is extremely noisy in code using DISALLOW_COPY_AND_ASSIGN-style macros and there's no easy way to automatically fix the warning when macros are in play. llvm-svn: 302425
* [clang-tidy] Use cxxStdInitializerListExpr in modernize-use-emplaceJakub Kuderski2017-05-051-9/+1
| | | | | | | | | | | | | | | | Summary: Use the cxxStdInitializerListExp matcher from ASTMatchers.h instead of a local one. Reviewers: aaron.ballman, alexfh, Prazek Reviewed By: aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32923 llvm-svn: 302317
* [clang-tidy] Fix PR32896: detect initializer lists in modernize-use-empalceJakub Kuderski2017-05-051-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: This patch fixes [[ https://bugs.llvm.org/show_bug.cgi?id=32896 | PR32896 ]]. The problem was that modernize-use-emplace incorrectly removed changed push_back into emplace_back, removing explicit constructor call with initializer list parameter, resulting in compiler error after applying fixits. modernize-use-emplace used to check if matched constructor had InitListExpr, but didn't check against CXXStdInitializerListExpr. Eg. ``` std::vector<std::vector<int>> v; v.push_back(std::vector<int>({1})); // --> v.emplace_back({1}); ``` Reviewers: Prazek, alexfh, aaron.ballman Reviewed By: Prazek, alexfh, aaron.ballman Subscribers: xazax.hun, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32767 llvm-svn: 302281
* [clang-tidy] Fix naming convention in modernize-use-emplaceJakub Kuderski2017-04-301-20/+20
| | | | | | | | | | | | | | | | Summary: Conform to the llvm naming convention for local variables in modernize-use-emplace check. Reviewers: Prazek, JonasToth, alexfh Reviewed By: Prazek, JonasToth, alexfh Subscribers: cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32678 llvm-svn: 301780
* [clang-tidy] modernize-use-emplace: remove unnecessary make_pair callsJakub Kuderski2017-04-281-14/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | Summary: When there is a push_back with a call to make_pair, turn it into emplace_back and remove the unnecessary make_pair call. Eg. ``` std::vector<std::pair<int, int>> v; v.push_back(std::make_pair(1, 2)); // --> v.emplace_back(1, 2); ``` make_pair doesn't get removed when explicit template parameters are provided, because of potential problems with type conversions. Reviewers: Prazek, aaron.ballman, hokein, alexfh Reviewed By: Prazek, alexfh Subscribers: JDevlieghere, JonasToth, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D32395 llvm-svn: 301651
* [clang-tidy] New check: modernize-replace-random-shuffle.Mads Ravn2017-04-244-0/+155
| | | | | | | | | | | | | | | | | | | | | | This check will find occurrences of ``std::random_shuffle`` and replace it with ``std::shuffle``. In C++17 ``std::random_shuffle`` will no longer be available and thus we need to replace it. Example of case that it fixes ``` std::vector<int> v; // First example std::random_shuffle(vec.begin(), vec.end()); ``` Reviewers: hokein, aaron.ballman, alexfh, malcolm.parsons, mclow.lists Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D30158 llvm-svn: 301167
* Fixes for modernize-use-using check:Krystyna Gajczyk2017-04-022-6/+25
| | | | | | | | | | | - removed unnessacary namespaces - added option to print warning in macros - no fix for typedef with array - removed "void" word from functions with 0 parameters Differential Revision: https://reviews.llvm.org/D29262 llvm-svn: 299340
* Apply clang-tidy's performance-unnecessary-value-param to clang-tidy.Benjamin Kramer2017-03-212-4/+4
| | | | | | No functionality change intended. llvm-svn: 298442
* [clang-tidy] Ignore substituted template types in modernize-use-nullptr check.Haojian Wu2017-03-061-0/+1
| | | | | | | | | | | | Reviewers: alexfh Reviewed By: alexfh Subscribers: xazax.hun, malcolm.parsons, JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30639 llvm-svn: 297009
* [clang-tidy] Fix handling of methods with try-statement as a body in ↵Alexander Kornienko2017-03-011-7/+6
| | | | | | | | | | | | | | | | | | | | | | | | | modernize-use-override Summary: Fix generated by modernize-use-override caused syntax error when method used try-statement as a body. `override` keyword was inserted after last declaration token which happened to be a `try` keyword. This fixes PR27119. Reviewers: ehsan, djasper, alexfh Reviewed By: alexfh Subscribers: JDevlieghere, cfe-commits Tags: #clang-tools-extra Patch by Paweł Żukowski! Differential Revision: https://reviews.llvm.org/D30002 llvm-svn: 296598
* [clang-tidy] Fix a false positive on modernize-use-nullptr check.Haojian Wu2017-02-281-1/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The false positive happens on two neighbour CXXDefaultArgExpr AST nodes. like below: ``` CXXFunctionalCastExpr 0x85c9670 <col:7, col:23> 'struct ZZ' functional cast to struct ZZ <ConstructorConversion> `-CXXConstructExpr 0x85c9518 <col:7, col:23> 'struct ZZ' 'void (uint64, const uint64 *)' |-CallExpr 0x85a0a90 <col:10, col:22> 'uint64':'unsigned long long' | |-ImplicitCastExpr 0x85a0a78 <col:10> 'uint64 (*)(uint64)' <FunctionToPointerDecay> | | `-DeclRefExpr 0x85a09f0 <col:10> 'uint64 (uint64)' lvalue Function 0x85a06a0 'Hash' 'uint64 (uint64)' | `-CXXDefaultArgExpr 0x85a0ac8 <<invalid sloc>> 'uint64':'unsigned long long' `-CXXDefaultArgExpr 0x85c94f8 <<invalid sloc>> 'const uint64 *' ``` For each particular CXXDefaultArgExpr node, we need to reset FirstSubExpr, otherwise FirstSubExpr will refer to an incorrect expr. Reviewers: alexfh Reviewed By: alexfh Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D30412 llvm-svn: 296479
* [clang-tidy] Add check 'modernize-return-braced-init-list'Jonas Devlieghere2017-02-154-0/+137
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: Replaces explicit calls to the constructor in a return with a braced initializer list. This way the return type is not needlessly duplicated in the return type and the return statement. ``` Foo bar() { Baz baz; return Foo(baz); } // transforms to: Foo bar() { Baz baz; return {baz}; } ``` Reviewers: hokein, Prazek, aaron.ballman, alexfh Reviewed By: Prazek, aaron.ballman, alexfh Subscribers: malcolm.parsons, mgorny, cfe-commits Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D28768 llvm-svn: 295199
* [clang-tidy] Remove debug logging.Alexander Kornienko2017-02-011-5/+0
| | | | llvm-svn: 293763
* Revert "Implement a new clang-tidy check that suggests users replace dynamic ↵Diana Picus2017-01-274-166/+0
| | | | | | | | | exception specifications with noexcept exception specifications." This reverts commit r293217, its follow-up 293218 and part of 293234 because it broke all bots that build clang-tools-extra. llvm-svn: 293267
* Implement a new clang-tidy check that suggests users replace dynamic ↵Aaron Ballman2017-01-264-0/+166
| | | | | | | | exception specifications with noexcept exception specifications. Patch by Don Hinton. llvm-svn: 293217
* [clang-tidy] Don't modernize-raw-string-literal if replacement is longer.Gabor Horvath2017-01-242-7/+17
| | | | | | | | | | Fixes PR30964. The old behavior can be achieved using a setting. Patch by: Andras Leitereg! Differential Revision: https://reviews.llvm.org/D28667 llvm-svn: 292938
* [clang-tidy] Avoid incorrect fixes in modernize-use-usingAlexander Kornienko2017-01-241-21/+38
| | | | | | | Avoid fixes for typedefs with multiple types and for typedefs with struct definitions. Partially addresses http://llvm.org/PR28334 llvm-svn: 292918
* [clang-tidy] Fix crash in modernize-use-using (http://llvm.org/PR29135)Alexander Kornienko2017-01-171-33/+26
| | | | llvm-svn: 292229
* [clang-tidy] Fix check for trivially copyable types in modernize-pass-by-valueMalcolm Parsons2017-01-121-1/+2
| | | | | | | | | | | | | | | Summary: rL270567 excluded trivially copyable types from being moved by modernize-pass-by-value, but it didn't exclude references to them. Change types used in the tests to not be trivially copyable. Reviewers: madsravn, aaron.ballman, alexfh Subscribers: JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D28614 llvm-svn: 291796
* [clang-tidy] Ignore default arguments in modernize-default-member-initMalcolm Parsons2017-01-041-1/+1
| | | | | | | | | | | | | | | | | Summary: Default member initializers cannot refer to constructor parameters, but modernize-default-member-init was trying to when the default constructor had default arguments. Change the check to ignore default arguments to the default constructor. Fixes PR31524. Reviewers: alexfh, aaron.ballman Subscribers: cfe-commits, JDevlieghere, Eugene.Zelenko Differential Revision: https://reviews.llvm.org/D28287 llvm-svn: 290972
* [clang-tidy] Make 2 checks register matchers for C++ only.Malcolm Parsons2016-12-271-0/+3
| | | | llvm-svn: 290633
* [clang-tidy] Remove local hasInClassInitializer matcher. NFCMalcolm Parsons2016-12-241-10/+7
| | | | llvm-svn: 290493
* [clang-tidy] Add modernize-use-default-member-init checkMalcolm Parsons2016-12-204-0/+290
| | | | | | | | | | | | Summary: Fixes PR18858 Reviewers: alexfh, hokein, aaron.ballman Subscribers: JDevlieghere, Eugene.Zelenko, Prazek, mgorny, cfe-commits, modocache Differential Revision: https://reviews.llvm.org/D26750 llvm-svn: 290202
* [clang-tidy] Remove duplicated check from move-constructor-initMalcolm Parsons2016-12-172-3/+9
| | | | | | | | | | | | | | | | | | | | Summary: An addition to the move-constructor-init check was duplicating the modernize-pass-by-value check. Remove the additional check and UseCERTSemantics option. Run the move-constructor-init test with both checks enabled. Fix modernize-pass-by-value false-positive when initializing a base class. Add option to modernize-pass-by-value to only warn about parameters that are already values. Reviewers: alexfh, flx, aaron.ballman Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D26453 llvm-svn: 290051
* [clang-tidy] Enhance modernize-use-auto to templated function castsMalcolm Parsons2016-12-151-4/+46
| | | | | | | | | | | | | | | | Summary: Use auto when declaring variables that are initialized by calling a templated function that returns its explicit first argument. Fixes PR26763. Reviewers: aaron.ballman, alexfh, staronj, Prazek Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits Differential Revision: https://reviews.llvm.org/D27166 llvm-svn: 289797
* modernize-use-auto NFC fixesPiotr Padlewski2016-12-142-3/+3
| | | | llvm-svn: 289656
* Remove trailing whitespace in docs and clang-tidy sources.Alexander Kornienko2016-12-132-2/+2
| | | | llvm-svn: 289547
OpenPOWER on IntegriCloud