summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-loop-convert-basic.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ClangTidy] Separate tests for infrastructure and checkersDmitri Gribenko2019-10-111-796/+0
| | | | | | | | | | | | | | | | | | | | Summary: This change moves tests for checkers and infrastructure into separate directories, making it easier to find infrastructure tests. Tests for checkers are already easy to find because they are named after the checker. Tests for infrastructure were difficult to find because they were outnumbered by tests for checkers. Now they are in a separate directory. Reviewers: jfb, jdoerfert, lebedev.ri Subscribers: srhines, nemanjai, aheejin, kbarton, christof, mgrang, arphaman, jfb, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D68807 llvm-svn: 374540
* Run ClangTidy tests in all C++ language modesDmitri Gribenko2019-05-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: I inspected every test and did one of the following: - changed the test to run in all language modes, - added a comment explaining why the test is only applicable in a certain mode, - limited the test to language modes where it passes and added a FIXME to fix the checker or the test. Reviewers: alexfh, lebedev.ri Subscribers: nemanjai, kbarton, arphaman, jdoerfert, lebedev.ri, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D62125 llvm-svn: 361131
* [clang-tidy] Recommit r360785 "modernize-loop-convert: impl const cast iter" ↵Don Hinton2019-05-151-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | with correct attribution Summary: modernize-loop-convert was not detecting implicit casts to const_iterator as convertible to range-based loops: std::vector<int> vec{1,2,3,4} for(std::vector<int>::const_iterator i = vec.begin(); i != vec.end(); ++i) { } Thanks to Don Hinton for advice. As well, this change adds a note for this check's applicability to code targeting OpenMP prior version 5 as this check will continue breaking compilation with `-fopenmp`. Thanks to Roman Lebedev for pointing this out. Fixes PR#35082 Patch by Torbjörn Klatt! Reviewed By: hintonda Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D61827 llvm-svn: 360788
* Revert [clang-tidy] modernize-loop-convert: impl const cast iterDon Hinton2019-05-151-7/+4
| | | | | | This reverts r360785 (git commit 42d28be802fe5beab18bc1a27f89894c0a290d44) llvm-svn: 360787
* [clang-tidy] modernize-loop-convert: impl const cast iterDon Hinton2019-05-151-4/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: modernize-loop-convert was not detecting implicit casts to const_iterator as convertible to range-based loops: std::vector<int> vec{1,2,3,4} for(std::vector<int>::const_iterator i = vec.begin(); i != vec.end(); ++i) { } Thanks to Don Hinton for advice. As well, this change adds a note for this check's applicability to code targeting OpenMP prior to version 5 as this check will continue breaking compilation with `-fopenmp`. Thanks to Roman Lebedev for pointing this out. Fixes PR#35082 Reviewed By: hintonda Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D61827 llvm-svn: 360785
* [clang-tidy] Fix "Name is not a simple identifier" assertion in ↵Haojian Wu2016-03-141-0/+4
| | | | | | | | | | | | | | | | | | | | | | `modernize-loop-convert` check. Summary: Fix assertion failure: "Name is not a simple identifier". `Decl::GetName` assumes the name should be an identifier. When the check processes the function calling statement with speciail key name like 'it.operator->()', it will trigger the assert in `GetName`. Rather than using `Decl::GetName`, we use `getNameAsString` which works with special key names in C++. Reviewers: bkramer Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18141 llvm-svn: 263426
* Use the old index identifier by default, instead of 'elem'.Angel Garcia Gomez2015-11-061-132/+132
| | | | | | | | | | | | Summary: Use the old index name in the cases where the check would come up with an invented name. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D14438 llvm-svn: 252308
* Handle correctly containers that are data members in modernize-loop-convert.Angel Garcia Gomez2015-11-031-0/+35
| | | | | | | | | | | | | | | | Summary: I recently found that the variable naming wasn't working as expected with containers that are data members. The new index always received the name "Elem" (or equivalent) regardless of the container's name. The check was assuming that the container's declaration was a VarDecl, which cannot be converted to a FieldDecl (a data member), and then it could never retrieve its name. This also fixes some cases where the check failed to find the container at all (so it didn't do any fix) because of the same reason. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14289 llvm-svn: 251943
* Make the modernize-loop-convert's const-detection smarter.Angel Garcia Gomez2015-11-021-21/+21
| | | | | | | | | | | | | | | | Summary: Now, it detects that several kinds of usages are can't modify the elements. Examples: -When an usage is a call to a const member function or operator of the element. -If the element is used as an argument to a function or constructor that takes a const-reference or a value. -LValue to RValue conversion, if the element is a fundamental type (which allows the use of most of the builtin operators). Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14198 llvm-svn: 251808
* Only copy small types in modernize-loop-convert.Angel Garcia Gomez2015-10-301-0/+8
| | | | | | | | | | | | Summary: If the size of the type is above a certain bound, we'll take a const reference. This bound can be set as an option. For now, the default value is 16 bytes. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14176 llvm-svn: 251694
* Switch check_clang_tidy to argparse and add a -resource-dir argument.Manuel Klimek2015-10-221-1/+1
| | | | | | | -resource-dir can be used to inject non-standard resource dirs via the lit site config. llvm-svn: 251021
* Don't use "auto" on loops over fundamental types in modernize-loop-convert.Angel Garcia Gomez2015-10-221-29/+81
| | | | | | | | | | | | Summary: using "auto" on a loop that iterates over ints is kind of an overkill. Use the real type name instead. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13982 llvm-svn: 251015
* Add %check_clang_tidy and %clang_tidy_diff.Manuel Klimek2015-10-221-1/+1
| | | | | | | | | | With this, site specific lit configs can inject parameters into the test scripts if they need site specific parameters. Next up: enable check_clang_tidy to take a resource dir to enable non-standard locations for builtin includes. llvm-svn: 251010
* Document a bug in loop-convert and fix one of its subcases.Angel Garcia Gomez2015-10-051-1/+11
| | | | | | | | | | | | Summary: Now that we prioritize copying trivial types over using const-references where possible, I found some cases where, after the transformation, the loop was using the address of the local copy instead of the original object. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13431 llvm-svn: 249300
* Add support for 'cbegin()' and 'cend()' on modernize-loop-convert.Angel Garcia Gomez2015-10-011-23/+39
| | | | | | | | | | | | | | | Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=22196 . Also add a non-trivially copyable type to fix some tests that were meant to be about using const-refs, but were changed in r248438. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13292 llvm-svn: 248994
* Add NamingStyle option to modernize-loop-convert.Angel Garcia Gomez2015-09-241-291/+291
| | | | | | | | | | | | Summary: Add an option to specify wich style must be followed when choosing the new index name. Reviewers: alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13052 llvm-svn: 248517
* Remove dangling parenthesis.Angel Garcia Gomez2015-09-241-6/+21
| | | | | | | | | | | | Summary: Remove parenthesis surrounding the new loop index. Reviewers: klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13133 llvm-svn: 248507
* Fix loop-convert for trivially copyable types.Manuel Klimek2015-09-231-11/+18
| | | | | | | | | | | | | | Previously, we would rewrite: void f(const vector<int> &v) { for (size_t i = 0; i < v.size(); ++i) { to for (const auto &elem : v) { Now we rewrite it to: for (auto elem : v) { (and similarly for iterator based loops). llvm-svn: 248438
* Fix loop-convert for const references to containers.Manuel Klimek2015-09-231-0/+12
| | | | | | | | | | | | Previously we would use a non-const loop variable in the range-based loop for: void f(const std::vector<int> &v) { for (size_t i = 0; i < v.size(); ++i) { Now we use const auto&. Note that we'll also want to use a copy at least for simple types. llvm-svn: 248418
* Refactor LoopConvertCheck.Angel Garcia Gomez2015-09-211-2/+2
| | | | | | | | | | | | Summary: Reorder the code in a more logical and understandable way. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D12797 llvm-svn: 248144
* Another patch for modernize-loop-convert.Angel Garcia Gomez2015-09-111-70/+118
| | | | | | | | | | | | | | | | | | Summary: 1. Avoid converting loops that iterate over the size of a container and don't use its elements, as this would result in an unused-result warning. 2. Never capture the elements by value on lambdas, thus avoiding doing unnecessary copies and errors with non-copyable types. 3. The 'const auto &' instead of 'auto &' substitution on const containers now works on arrays and pseudoarrays as well. 4. The error about multiple replacements in the same macro call is now documented in the tests (not solved though). 5. Due to [1], I had to add a dummy usage of the range element (like "(void) *It;" or similars) on the tests that had empty loops. 6. I removed the braces from the CHECK comments. I think that there is no need for them, and they confuse vim. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12734 llvm-svn: 247399
* Avoid using rvalue references with trivially copyable types.Angel Garcia Gomez2015-09-081-3/+12
| | | | | | | | | | | | | | | | Summary: When the dereference operator returns a value that is trivially copyable (like a pointer), copy it. After this change, modernize-loop-convert check can be applied to the whole llvm source code without breaking any build or test. Reviewers: alexfh, klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12675 llvm-svn: 246989
* Fix loop-convert crash.Angel Garcia Gomez2015-09-021-0/+11
| | | | | | | | | | | | Summary: loop-convert no longer crashes when calling a member function using a member pointer which is a member of another record. Reviewers: alexfh, klimek Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D12555 llvm-svn: 246655
* Fix several corner cases for loop-convert check.Angel Garcia Gomez2015-09-011-8/+27
| | | | | | | | | | | | Summary: Reduced the amount of wrong conversions of this check. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12530 llvm-svn: 246550
* [clang-tidy] Use a python script instead of a shell script to run clang-tidy ↵Alexander Kornienko2015-08-201-2/+1
| | | | | | | | | | | | | | | | | | | tests. Summary: Add check_clang_tidy.py script that is functionally identical to the check_clang_tidy.py, but should also be functional on windows. I've verified that the script works on linux. Would be nice if folks using Windows could test the patch before I break windows bots ;) Reviewers: chapuni, aaron.ballman Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D12180 llvm-svn: 245583
* [clang-tidy] Add loop-convert check to clang-tidy.Alexander Kornienko2015-08-191-0/+548
Move LoopConvert from clang-modernize to modernize module in clang-tidy. http://reviews.llvm.org/D12076 Patch by Angel Garcia! llvm-svn: 245427
OpenPOWER on IntegriCloud