summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/modernize-loop-convert-extra.cpp
Commit message (Collapse)AuthorAgeFilesLines
* [ClangTidy] Separate tests for infrastructure and checkersDmitri Gribenko2019-10-111-1085/+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/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-15/+4
| | | | | | This reverts r360785 (git commit 42d28be802fe5beab18bc1a27f89894c0a290d44) llvm-svn: 360787
* [clang-tidy] modernize-loop-convert: impl const cast iterDon Hinton2019-05-151-4/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 modernize-loop-convert: preserve type of alias declaration (bug ↵Matthias Gehre2016-07-201-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 28341) Summary: Previoly, the added test failed with the fillowing fixit: char v[5]; - for(size_t i = 0; i < 5; ++i) + for(char value : v) { - unsigned char value = v[i]; if (value > 127) i.e. the variable 'value' changes from unsigned char to signed char. And thus the following 'if' does not work anymore. With this commit, the fixit is changed to: char v[5]; - for(size_t i = 0; i < 5; ++i) + for(unsigned char value : v) { - unsigned char value = v[i]; if (value > 127) Reviewers: alexfh, klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D22069 llvm-svn: 276111
* [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.Haojian Wu2016-02-081-0/+8
| | | | | | | | | | Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16926 llvm-svn: 260107
* Allow the alias to be of a different type.Angel Garcia Gomez2015-11-061-1/+20
| | | | | | | | | | | | Summary: Consider a declaration an alias even if it doesn't have the same unqualified type than the container element, as long as one can be converted to the other using only implicit casts. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14442 llvm-svn: 252315
* Use the old index identifier by default, instead of 'elem'.Angel Garcia Gomez2015-11-061-122/+122
| | | | | | | | | | | | 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
* Avoid naming conflicts with the old index in modernize-loop-convert.Angel Garcia Gomez2015-11-061-0/+17
| | | | | | | | | | | | Summary: The old index declaration is going to be removed anyway, so we can reuse its name if it is the best candidate for the new index. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14437 llvm-svn: 252303
* Fix another case where loop-convert wasn't handling correctly data members.Angel Garcia Gomez2015-11-061-0/+25
| | | | | | | | | | | | | | | Summary: If the container expression was obtained from the point where "size" (which usually is a const method) is invoked, then the topmost node in this expression may be an implicit cast to const. When the container is a data member, the check was trying to obtain the member expression directly and was failing in the case mentioned above. This is solved by ignoring implicit casts. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14378 llvm-svn: 252278
* Handle correctly containers that are data members in modernize-loop-convert.Angel Garcia Gomez2015-11-031-0/+20
| | | | | | | | | | | | | | | | 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-12/+12
| | | | | | | | | | | | | | | | 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
* 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-37/+37
| | | | | | | | | | | | 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
* Prevent loop-convert from leaving empty lines after removing an alias ↵Angel Garcia Gomez2015-10-011-10/+20
| | | | | | | | | | | | | | declaration. Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=17716. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13342 llvm-svn: 249006
* Add NamingStyle option to modernize-loop-convert.Angel Garcia Gomez2015-09-241-362/+374
| | | | | | | | | | | | 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-11/+11
| | | | | | | | | | | | 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-6/+6
| | | | | | | | | | | | | | 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
* Add a test to modernize-loop-convert.Angel Garcia Gomez2015-09-171-15/+9
| | | | | | | | | | | | Summary: Add the test about replacements in several arguments of the same macro call, now that the problem has been fixed. Reviewers: alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D12933 llvm-svn: 247889
* Another patch for modernize-loop-convert.Angel Garcia Gomez2015-09-111-40/+82
| | | | | | | | | | | | | | | | | | 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 repeated replacements on loop-convert check.Angel Garcia Gomez2015-09-041-0/+29
| | | | | | | | | | | | Summary: The InitListExpr subtree is visited twice, this caused the check to do multiple replacements. Added a set to avoid it. Reviewers: klimek, alexfh Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D12631 llvm-svn: 246879
* Two more fixes to loop convert.Angel Garcia Gomez2015-09-031-0/+171
| | | | | | | | | | | | Summary: Ensure that the alias has the same type than the loop variable. Now it works with lambda captures. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D12597 llvm-svn: 246762
* Fix several corner cases for loop-convert check.Angel Garcia Gomez2015-09-011-0/+50
| | | | | | | | | | | | 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
* Fix another LoopConvert fail.Angel Garcia Gomez2015-08-261-1/+7
| | | | | | | | | | | | Summary: Prevent LoopConvert from taking as alias anything that comes from a random member function call. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D12370 llvm-svn: 246039
* LoopConvert no longer take as alias references to other containers.Angel Garcia Gomez2015-08-261-0/+10
| | | | | | | | | | | | Summary: Fix a bug where modernize-loop-convert check would take as alias a reference to other containers. Add the pertinent test. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D12361 llvm-svn: 246034
* Avoid LoopConvertCheck replacements in template instantiations.Angel Garcia Gomez2015-08-251-0/+21
| | | | | | | | | | | | Summary: Prevent LoopConvertCheck from doing replacements in template instantiations, and add a test. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D12321 llvm-svn: 245942
* [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] Fix bug in modernize-loop-convert check.Alexander Kornienko2015-08-201-0/+21
| | | | | | | | http://reviews.llvm.org/D12186 Patch by Angel Garcia! llvm-svn: 245561
* [clang-tidy] Add loop-convert check to clang-tidy.Alexander Kornienko2015-08-191-0/+608
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