summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix crashes from delayed template parsing code that assumed getBody() would ↵Aaron Ballman2016-03-221-6/+4
| | | | | | | | return non-null. Patch by Etienne Bergeron. llvm-svn: 264049
* [clang-tidy] Fix "Name is not a simple identifier" assertion in ↵Haojian Wu2016-03-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | `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
* [clang-tidy] Make 'modernize-use-nullptr' check ignores NULL marcos used in ↵Haojian Wu2016-03-111-0/+6
| | | | | | | | | | | | other macros. Reviewers: bkramer, alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17958 llvm-svn: 263221
* [clang-tidy] Make 'modernize-use-nullptr' check work on multiple nested ↵Haojian Wu2016-03-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | implicit cast expressions. Summary: For some test cases like: ``` int func(int, void*, void*); (double)func(0, 0, 0); ``` The AST contains several `ImplicitCastExpr`s, so we should not only check on the first sub expression. ``` `-CStyleCastExpr 0x7fe43a088938 <line:6:3, col:24> 'double' <NoOp> `-ImplicitCastExpr 0x7fe43a088920 <col:11, col:24> 'double' <IntegralToFloating> `-CallExpr 0x7fe43a0888a0 <col:11, col:24> 'int' |-ImplicitCastExpr 0x7fe43a088888 <col:11> 'int (*)(int, void *, void *)' <FunctionToPointerDecay> | `-DeclRefExpr 0x7fe43a0887d8 <col:11> 'int (int, void *, void *)' lvalue Function 0x7fe43a0886f0 'func1' 'int (int, void *, void *)' |-IntegerLiteral 0x7fe43a088800 <col:17> 'int' 0 |-ImplicitCastExpr 0x7fe43a0888e0 <col:20> 'void *' <NullToPointer> | `-IntegerLiteral 0x7fe43a088820 <col:20> 'int' 0 `-ImplicitCastExpr 0x7fe43a0888f8 <col:23> 'void *' <NullToPointer> `-IntegerLiteral 0x7fe43a088840 <col:23> 'int' 0 ``` Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17849 llvm-svn: 262698
* [clang-tidy] Make 'modernize-pass-by-value' fix work on header files.Haojian Wu2016-03-021-5/+6
| | | | | | | | | | Reviewers: alexfh Subscribers: jbcoe, cfe-commits Differential Revision: http://reviews.llvm.org/D17756 llvm-svn: 262470
* [clang-tidy] Fix an assertion failure in `modernize-use-nullptr` check.Haojian Wu2016-02-261-1/+1
| | | | | | | | | | Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D17640 llvm-svn: 262024
* [clang-tidy] Another attempt to fix MSVC buildAlexander Kornienko2016-02-251-13/+17
| | | | llvm-svn: 261811
* Trying to fix MSVC buildAlexander Kornienko2016-02-241-23/+14
| | | | llvm-svn: 261806
* [clang-tidy] introduce modernize-deprecated-headers checkAlexander Kornienko2016-02-244-0/+156
| | | | | | | | | | | | | | | | | Summary: This patch introduces the modernize-deprecated-headers check, which is supposed to replace deprecated C library headers with the C++ STL-ones. For information see documentation; for exmaples see the test cases. Reviewers: Eugene.Zelenko, LegalizeAdulthood, alexfh Subscribers: cfe-commits Patch by Kirill Bobyrev! Differential Revision: http://reviews.llvm.org/D17484 llvm-svn: 261738
* [clang-tidy] Fix an assert failure in `modernize-loop-convert`.Haojian Wu2016-02-161-1/+3
| | | | | | | | | | | | | | Summary: The test code will trigger following an assert failure: assert.h assertion failed at LoopConvertUtils.cpp:560 in bool clang::tidy::modernize::ForLoopIndexUseVisitor::TraverseMemberExpr(clang::MemberExpr*): ExprType->isPointerType() && "Operator-> returned non-pointer type" Reviewers: alexfh Differential Revision: http://reviews.llvm.org/D17287 llvm-svn: 260953
* [clang-tidy] Enhance modernize-redundant-void-arg check to apply fixes to ↵Alexander Kornienko2016-02-161-22/+10
| | | | | | | | | | | | header files Fixes http://llvm.org/PR25894 Patch by Richard Thomson! Differential revision: http://reviews.llvm.org/D16953 llvm-svn: 260948
* [clang-tidy] Fix assertion failure on `at` function in modernize-loop-convert.Haojian Wu2016-02-081-2/+2
| | | | | | | | | | Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D16926 llvm-svn: 260107
* Remove autoconf supportChris Bieneman2016-01-261-12/+0
| | | | | | | | | | | | | | | | Summary: This patch is provided in preparation for removing autoconf on 1/26. The proposal to remove autoconf on 1/26 was discussed on the llvm-dev thread here: http://lists.llvm.org/pipermail/llvm-dev/2016-January/093875.html "Now I am become Death, the destroyer of worlds." -J. Robert Oppenheimer Reviewers: chandlerc, grosbach, bob.wilson, echristo Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D16475 llvm-svn: 258864
* Make modernize-use-default tolerant of delayed template parsing; this code ↵Aaron Ballman2016-01-201-0/+1
| | | | | | was previously causing failed assertions because dyn_cast was being passed a null pointer due to the delay-parsed body. llvm-svn: 258356
* Replace a dyn_cast with isa where the result was only being used as a ↵Craig Topper2015-11-181-1/+1
| | | | | | boolean. NFC. llvm-svn: 253442
* Allow the alias to be of a different type.Angel Garcia Gomez2015-11-061-12/+18
| | | | | | | | | | | | 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-48/+1
| | | | | | | | | | | | 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-5/+6
| | | | | | | | | | | | 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-3/+3
| | | | | | | | | | | | | | | 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
* Improve modernize-make-unique matcher.Angel Garcia Gomez2015-11-041-3/+4
| | | | | | | | | | | | Summary: "std::unique_ptr<int>" is not the same type as "std::unique_ptr<int, std::default_delete<int>>", unless we insert a "hasCanonicalType" in the middle. Probably it also happens in other cases related to default template argument. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14291 llvm-svn: 252041
* Handle correctly containers that are data members in modernize-loop-convert.Angel Garcia Gomez2015-11-033-8/+11
| | | | | | | | | | | | | | | | 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
* Improve more the const-detection in modernize-loop-convert.Angel Garcia Gomez2015-11-031-0/+2
| | | | | | | | | | | | Summary: The previous change was focused in detecting when a non-const object was used in a constant way. Looks like I forgot the most important and trivial case: when the object is already constant. Failing to detect this cases results in compile errors, due to trying to bind a constant object to a non-const reference in the range-for statement. This change should fix that. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D14282 llvm-svn: 251940
* Make the modernize-loop-convert's const-detection smarter.Angel Garcia Gomez2015-11-021-7/+33
| | | | | | | | | | | | | | | | 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
* Fix another crash in the redundant-void-arg check.Angel Garcia Gomez2015-11-021-3/+6
| | | | | | | | | | | | Summary: The check was assuming that a definition of a function always has a body, but a declaration that explicitly defaults or deletes a function is a definition too. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14238 llvm-svn: 251807
* Remove unreachable that was reached in modernize-use-nullptr.Angel Garcia Gomez2015-11-021-5/+7
| | | | | | | | | | | | Summary: When traversing the parent map, the check assumed that all the nodes would be either Stmt or Decl. After r251101, this is no longer true: there can be TypeLoc and NestedNameSpecifierLoc nodes. Reviewers: alexfh Subscribers: klimek, cfe-commits Differential Revision: http://reviews.llvm.org/D14229 llvm-svn: 251803
* Fix crash in redundant-void-arg check.Angel Garcia Gomez2015-11-021-10/+14
| | | | | | | | | | | | | | Summary: When applying this check to the unit tests, it would hit an assertion: llvm/tools/clang/lib/Lex/Lexer.cpp:1056: clang::SourceLocation clang::Lexer::getSourceLocation(const char*, unsigned int) const: Assertion `PP && "This doesn't work on raw lexers"' failed. Reviewers: klimek, LegalizeAdulthood, alexfh Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14204 llvm-svn: 251792
* modernize-use-default supports copy constructor and copy-assignment operator.Angel Garcia Gomez2015-11-021-24/+282
| | | | | | | | | | | | Summary: the check will now warn when the user provided definitions of this functions is equivalent to the explicitly defaulted ones. Reviewers: klimek Subscribers: klimek, cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D14145 llvm-svn: 251788
* Only copy small types in modernize-loop-convert.Angel Garcia Gomez2015-10-303-15/+24
| | | | | | | | | | | | 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
* Add modernize-redundant-void-arg check to clang-tidyAlexander Kornienko2015-10-284-0/+334
| | | | | | | | | | | | | | | | | | | | | This check for clang-tidy looks for function with zero arguments declared as (void) and removes the unnecessary void token. int foo(void); becomes int foo(); The check performs no formatting of the surrounding context but uses the lexer to look for the token sequence "(", "void", ")" in the prototype text. If this sequence of tokens is found, a removal is issued for the void token only. Patch by Richard Thomson! (+fixed tests, moved the check to the modernize module) Differential revision: http://reviews.llvm.org/D7639 llvm-svn: 251475
* Don't use "auto" on loops over fundamental types in modernize-loop-convert.Angel Garcia Gomez2015-10-222-20/+19
| | | | | | | | | | | | 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
* Correctly print the type in modernize-make-unique.Angel Garcia Gomez2015-10-221-2/+2
| | | | | | | | | | | | Summary: Take into account the current LangOptions the check has to add back the template argument. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13983 llvm-svn: 251013
* Make string constants in the modernize module static.Angel Garcia Gomez2015-10-223-18/+18
| | | | | | | | | | | | Summary: Add static to global variables, if they are not in an anonymous namespace. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13975 llvm-svn: 251005
* Add modernize-use-default check to clang-tidy.Angel Garcia Gomez2015-10-214-3/+119
| | | | | | | | | | | | | | | | | | | Summary: Add a check that replaces empty bodies of special member functions with '= default;'. For now, it is only implemented for the default constructor and the destructor, which are the easier cases. The copy-constructor and the copy-assignment operator cases will be implemented later. I applied this check to the llvm code base and found 627 warnings (385 in llvm, 9 in compiler-rt, 220 in clang and 13 in clang-tools-extra). Applying the fixes didn't break any build or test, it only caused a -Wpedantic warning in lib/Target/Mips/MipsOptionRecord.h:33 becaused it replaced virtual ~MipsOptionRecord(){}; to virtual ~MipsOptionRecord()= default;; Reviewers: klimek Subscribers: george.burgess.iv, Eugene.Zelenko, alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13871 llvm-svn: 250897
* Make a bunch of static arrays const.Craig Topper2015-10-182-13/+15
| | | | llvm-svn: 250641
* Prevent modernize-use-auto from emitting a warning when 'auto' was already ↵Angel Garcia Gomez2015-10-141-0/+3
| | | | | | | | | | | | | | being used. Summary: This fixes https://llvm.org/bugs/show_bug.cgi?id=25082 . Reviewers: bkramer, klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13504 llvm-svn: 250284
* Support every kind of initialization.Angel Garcia Gomez2015-10-141-3/+41
| | | | | | | | | | | | Summary: modernize-make-unique now correctly supports the different kinds of list initialization. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13590 llvm-svn: 250283
* Improved the misc-move-constructor-init check to identify arguments that are ↵Aaron Ballman2015-10-062-9/+6
| | | | | | | | passed by value but copy assigned to class data members when the non-deleted move constructor is a better fit. Patch by Felix Berger! llvm-svn: 249429
* Use better mocks in modernize-make-unique, and fix matcher.Angel Garcia Gomez2015-10-051-3/+11
| | | | | | | | | | | | Summary: Add the second template argument to the unique_ptr mock, and update the matcher so that it only matches against cases where the second argument is the default. Reviewers: klimek Subscribers: alexfh, cfe-commits Differential Revision: http://reviews.llvm.org/D13433 llvm-svn: 249305
* Document a bug in loop-convert and fix one of its subcases.Angel Garcia Gomez2015-10-051-2/+15
| | | | | | | | | | | | 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
* Fix bug in modernize-use-nullptr.Angel Garcia Gomez2015-10-051-7/+24
| | | | | | | | | | | | | | | | | Summary: https://llvm.org/bugs/show_bug.cgi?id=24960 modernize-use-nullptr would hit an assertion in some cases involving macros and initializer lists, due to finding a node with more than one parent (the two forms of the initializer list). However, this doesn't mean that the replacement is incorrect, so instead of just rejecting this case I tried to find a way to make it work. Looking at the semantic form of the InitListExpr made sense to me (looking at both forms results in false negatives) but I am not sure of the things that we can miss by skipping the syntactic form. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13246 llvm-svn: 249291
* Replace double negation of !FileID.isInvalid() with FileID.isValid().Yaron Keren2015-10-031-1/+1
| | | | | | +couple more of double-negated !SourceLocation.isInvalid() unfixed in r249228. llvm-svn: 249235
* Handle trailing underscores on modernize-loop-convert variable namer.Angel Garcia Gomez2015-10-021-0/+11
| | | | | | | | | | | | Summary: https://llvm.org/bugs/show_bug.cgi?id=24961. Reviewers: klimek Subscribers: cfe-commits, alexfh Differential Revision: http://reviews.llvm.org/D13381 llvm-svn: 249127
* Prevent loop-convert from leaving empty lines after removing an alias ↵Angel Garcia Gomez2015-10-012-1/+30
| | | | | | | | | | | | | | 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 support for 'cbegin()' and 'cend()' on modernize-loop-convert.Angel Garcia Gomez2015-10-011-5/+8
| | | | | | | | | | | | | | | 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
* Create modernize-make-unique check.Angel Garcia Gomez2015-09-294-0/+153
| | | | | | | | | | | | Summary: create a check that replaces 'std::unique_ptr<type>(new type(args...))' with 'std::make_unique<type>(args...)'. It was on the list of "Ideas for new Tools". It needs to be tested more carefully, but first I wanted to know if you think it is worth the effort. Reviewers: klimek Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D13166 llvm-svn: 248785
* Add NamingStyle option to modernize-loop-convert.Angel Garcia Gomez2015-09-245-24/+85
| | | | | | | | | | | | 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-1/+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
* Solve comment on rL248418.Angel Garcia Gomez2015-09-241-3/+1
| | | | | | | | | | | | Summary: Solve comment on rL248418. Reviewers: alexfh Subscribers: cfe-commits, klimek Differential Revision: http://reviews.llvm.org/D13129 llvm-svn: 248489
* Use simpler interface for getting the pointee type for a node.Manuel Klimek2015-09-241-1/+1
| | | | llvm-svn: 248449
* Fix loop-convert for trivially copyable types.Manuel Klimek2015-09-231-31/+32
| | | | | | | | | | | | | | 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
OpenPOWER on IntegriCloud