summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/readability
Commit message (Collapse)AuthorAgeFilesLines
* [clang-tidy] Enhance clang-tidy readability-simplify-boolean-expr...Alexander Kornienko2015-07-012-29/+276
| | | | | | | | | | | | | | | | | | | | Enhance clang-tidy readability-simplify-boolean-expr to handle 'if (e) return true; return false;' and improve replacement expressions. This changeset extends the simplify boolean expression check in clang-tidy to simplify if (e) return true; return false; to return e; (note the lack of an else clause on the if statement.) By default, chained conditional assignment is left unchanged, unless a configuration parameter is set to non-zero to override this behavior. It also improves the handling of replacement expressions to apply static_cast<bool>(expr) when expr is not of type bool. http://reviews.llvm.org/D9810 Patch by Richard Thomson! llvm-svn: 241155
* [clang-tidy] Move user-defined matches to unnamed namespaces to prevent ODR ↵Alexander Kornienko2015-06-172-10/+6
| | | | | | violations. llvm-svn: 239904
* [clang-tidy] Force braces around leaf 'else if' for consistency.Samuel Benzaquen2015-06-042-5/+14
| | | | | | | | | | | | | | Summary: Force braces around leaf 'else if' for consistency. This complements r233697. Reviewers: alexfh Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D10245 llvm-svn: 239054
* [clang-tidy] Enhance clang-tidy readability-simplify-boolean-expr check...Alexander Kornienko2015-05-172-16/+55
| | | | | | | | | | | | | | | | Enhance clang-tidy readability-simplify-boolean-expr check to handle chained conditional assignment and chained conditional return. Based on feedback from applying this tool to the clang/LLVM codebase, this changeset improves the readability-simplify-boolean-expr check so that conditional assignment or return statements at the end of a chain of if/else if statements are left unchanged unless a configuration option is supplied. http://reviews.llvm.org/D8996 Patch by Richard Thomson! llvm-svn: 237541
* clang-tidy: [readability-else-after-return] Fix false positive. ThisDaniel Jasper2015-04-271-3/+5
| | | | | | | might be a little too strict now, but better be too strict than do the wrong thing. llvm-svn: 235932
* [clang-tidy] Remove static StringSet in favor of binary search.Benjamin Kramer2015-04-172-37/+29
| | | | | | | | The number of strings is so small that performance doesn't matter and adding the thread safe static initialization and destruction overhead is just not worth it. No functional change intended. llvm-svn: 235192
* [clang-tidy] Add readability-simplify-boolean-expr check to clang-tidyAlexander Kornienko2015-04-104-1/+482
| | | | | | | | | | | | | | | | | | | | | | | | | | | This check looks for comparisons between boolean expressions and boolean constants and simplifies them to just use the appropriate boolean expression directly. if (b == true) becomes if (b) if (b == false) becomes if (!b) if (b && true) becomes if (b) if (b && false) becomes if (false) if (b || true) becomes if (true) if (b || false) becomes if (b) e ? true : false becomes e e ? false : true becomes !e if (true) t(); else f(); becomes t(); if (false) t(); else f(); becomes f(); if (e) return true; else return false; becomes return (e); if (e) return false; else return true; becomes return !(e); if (e) b = true; else b = false; becomes b = e; if (e) b = false; else b = true; becomes b = !(e); http://reviews.llvm.org/D7648 Patch by Richard Thomson! llvm-svn: 234626
* [clang-tidy] Fix for http://llvm.org/PR23130Alexander Kornienko2015-04-081-3/+3
| | | | | | | NamespaceCommentCheck: Don't remove the token placed immediately after the namespace closing brace. llvm-svn: 234403
* Force braces on the else branch if they are being added to the if branch.Samuel Benzaquen2015-03-312-12/+15
| | | | | | | | | | | | | | Summary: Force braces on the else branch if they are being added to the if branch. This ensures consistency in the transformed code. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D8708 llvm-svn: 233697
* Make helpers static. clang-tools edition.Benjamin Kramer2015-03-231-3/+4
| | | | | | Also purge dead code found by it. NFC. llvm-svn: 232948
* [clang-tidy] Move google-readability-function check to ↵Alexander Kornienko2015-03-164-0/+170
| | | | | | | | | | | | | | | | readability-named-parameter. Summary: The relevant style rule is going to be removed, thus the check is no longer needed in the Google module. Leaving the check in readability/ in case someone needs it. Reviewers: djasper Reviewed By: djasper Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D8261 llvm-svn: 232431
* Move remove-cstr-calls from a standalone executable to a clang-tidy check ↵Alexander Kornienko2015-03-164-7/+180
| | | | | | | | | | readability-redundant-string-cstr http://reviews.llvm.org/D7318 Patch by Richard Thomson! llvm-svn: 232338
* [clang-tidy] Fixed header guards using clang-tidy llvm-header-guard check. NFC.Alexander Kornienko2015-03-092-6/+6
| | | | | | | | | | The patch was generated using this command: $ clang-tidy/tool/run-clang-tidy.py -header-filter=.*clang-tidy.* -fix \ -checks=-*,llvm-header-guard clang-tidy.* $ svn revert --recursive clangt-tidy/llvm/ (to revert a few buggy fixes) llvm-svn: 231669
* [clang-tidy] Refactor: Rename clang-tidy readability check files and classes ↵Alexander Kornienko2015-03-098-29/+28
| | | | | | | | | | | | | to follow naming conventions Classes are named WhateverCheck, files are WhateverCheck.cpp and` WhateverCheck.h` http://reviews.llvm.org/D8144 Patch by Richard Thomson! llvm-svn: 231650
* Use std::string instead of StringRef to prevent use-after-free.Daniel Jasper2015-03-051-1/+1
| | | | | | Discovered by asan. llvm-svn: 231421
* [clang-tidy] Replace unrecognized namespace ending comments.Alexander Kornienko2015-03-051-17/+22
| | | | | | | | | | | | | | | | | | | | | | Summary: Replace unrecognized namespace ending comments. This will help in particular when a namespace ending comment is mistyped or doesn't fit the regexp for other reason, e.g.: namespace a { namespace b { namespace { } // anoynmous namespace } // b } // namesapce a Reviewers: djasper Reviewed By: djasper Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D8078 llvm-svn: 231369
* [clang-tidy] Fix namespace comments. NFC.Alexander Kornienko2015-03-042-5/+5
| | | | llvm-svn: 231267
* [clang-tidy] Refactor: Move readability checks to namespace ↵Alexander Kornienko2015-03-024-2/+8
| | | | | | | | | | | | | clang::tidy::readability clang-tidy checks are organized into modules. This refactoring moves the readability module checks into the namespace clang::tidy::readability http://reviews.llvm.org/D7997 Patch by Richard Thomson! llvm-svn: 230946
* Re-sort includes using the LLVM utils/sort_includes.py script.Chandler Carruth2015-02-132-7/+4
| | | | llvm-svn: 229087
* [clang-tidy] Use shrink_to_fit instead of copy and swap trickAlexander Kornienko2015-01-234-0/+148
| | | | | | | | | | | | | | | | The shrink_to_fit() method is more readable and more effective than the copy and swap trick to reduce the capacity of a shrinkable container. Note that, the shrink_to_fit() method is only available in C++11 and up. Example: std::vector<int>(v).swap(v); will be replaced with v.shrink_to_fit(); http://reviews.llvm.org/D7087 Patch by Gábor Horváth! llvm-svn: 226912
* [clang-tidy] Small readability-container-size-empty cleanupAlexander Kornienko2015-01-231-2/+1
| | | | | | | | | | Utilized the hasEitherOperand instead of explicit anyOf. http://reviews.llvm.org/D7142 Patch by Gábor Horváth! llvm-svn: 226911
* [clang-tidy] Use actual LangOptions.Alexander Kornienko2015-01-222-4/+4
| | | | llvm-svn: 226812
* [clang-tidy] Minor cleanups in readability-container-size-empty checkerAlexander Kornienko2015-01-221-13/+6
| | | | | | | | | | | * Removed an unused header * Simplified the custom ast_matchers http://reviews.llvm.org/D7088 Patch by Gábor Horváth! llvm-svn: 226810
* clang-tidy: 'size' call that could be replaced with 'empty' on STL containersAlexander Kornienko2015-01-154-0/+217
| | | | | | | | | | | | | | | | | | | | | | | | | | | | We are porting some of the checkers at a company we developed to the Clang Tidy infrastructure. We would like to open source the checkers that may be useful for the community as well. This patch is the first checker that is being ported to Clang Tidy. We also added fix-it hints, and applied them to LLVM: http://reviews.llvm.org/D6924 The code compiled and the unit tests are passed after the fixits was applied. The documentation of the checker: /// The emptiness of a container should be checked using the empty method /// instead of the size method. It is not guaranteed that size is a /// constant-time function, and it is generally more efficient and also shows /// clearer intent to use empty. Furthermore some containers may implement the /// empty method but not implement the size method. Using empty whenever /// possible makes it easier to switch to another container in the future. It also uses some custom ASTMatchers. In case you find them useful I can submit them as separate patches to clang. I will apply your suggestions to this patch. http://reviews.llvm.org/D6925 Patch by Gábor Horváth! llvm-svn: 226172
* clang-tidy: Add initial check for "Don't use else after return".Daniel Jasper2015-01-144-0/+80
| | | | | | | | | | | As per the LLVM coding standards: http://llvm.org/docs/CodingStandards.html#don-t-use-else-after-a-return Initial version, probably still quite a bit to do until this is really useful. Review: http://reviews.llvm.org/D6927 llvm-svn: 226025
* [clang-tidy] Move the missing namespace comment warnings to the closing braceAlexander Kornienko2014-11-171-1/+9
| | | | | | | | | | | | | | | | | | | Summary: The google-readability-namespace-comments/llvm-namespace-comment warnings are quite confusing when they appear at the beginning of a long namespace and the closing brace is not in sight. For convenience added notes pointing to the start of the namespace. Reviewers: klimek Reviewed By: klimek Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D6251 llvm-svn: 222145
* [clang-tidy] Bring order to check registration.Alexander Kornienko2014-10-262-1/+46
| | | | | | | | | | | | | | | | Summary: Register readability checks in a separate module. Renamed the checks and test file names accordingly. Reviewers: djasper, klimek Reviewed By: klimek Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5936 llvm-svn: 220631
* [clang-tidy] Minor fixes for the NamespaceCommentCheck.Alexander Kornienko2014-10-161-4/+6
| | | | | | | | * Make SmallVector size enough for all groups. * Allow trailing period in the comment. * Fix "// anonymous namespace qqq". llvm-svn: 219926
* [clang-tidy] Default options in modules.Alexander Kornienko2014-10-161-2/+1
| | | | | | | | | | | | | | | | | | | | | | | Summary: This patch allows modules to specify default options for the checks defined in them. This way a sufficiently configurable check can be registered in multiple modules with different default options. E.g. the SpacesBeforeComments option may be set to 1 for the "llvm-namespace-comments" check and to 2 for the "google-readability-namespace-comment" check without modifying or extending the check code. This patch also registers the google-readability-braces-around-statements check with suitable defaults. Reviewers: djasper Reviewed By: djasper Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5798 llvm-svn: 219923
* [clang-tidy] Move some of the misc checks to readability/Alexander Kornienko2014-10-157-0/+636
| | | | | | | | | | | | | | | | | | | Summary: Some of the misc checks belong to readability/. I'm moving them there without changing check names for now. As the next step, I want to register some of these checks in the google and llvm modules with suitable settings (e.g. BracesAroundStatementsCheck). I'm not sure if we want to create a "readability" module, probably not. Reviewers: djasper Reviewed By: djasper Subscribers: curdeius, cfe-commits Differential Revision: http://reviews.llvm.org/D5792 llvm-svn: 219786
* Add NamespaceCommentCheck to the Google module.Alexander Kornienko2014-09-224-0/+194
Summary: This uses a bit hacky way to set the defaults for the spaces before comments, but it's also one of the simplest ways. Fixed a bug with how the SpacesBeforeComments option was used. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D5410 llvm-svn: 218240
OpenPOWER on IntegriCloud