summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/cppcoreguidelines
Commit message (Collapse)AuthorAgeFilesLines
* Adding the readability module to the list of dependencies for the C++ Core ↵Aaron Ballman2018-08-121-0/+1
| | | | | | Guidelines module. Amends r339516 for a failing bot. llvm-svn: 339517
* Add a new check to the readability module that flags uses of "magic numbers" ↵Aaron Ballman2018-08-121-0/+3
| | | | | | | | (both floating-point and integral). Patch by Florin Iucha <florin@signbit.net> llvm-svn: 339516
* Port getLocEnd -> getEndLocStephen Kelly2018-08-093-3/+3
| | | | | | | | Subscribers: nemanjai, ioeric, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D50355 llvm-svn: 339401
* Port getLocStart -> getBeginLocStephen Kelly2018-08-096-28/+28
| | | | | | | | | | Reviewers: javed.absar Subscribers: nemanjai, kbarton, ilya-biryukov, ioeric, jkorous, arphaman, jfb, cfe-commits Differential Revision: https://reviews.llvm.org/D50354 llvm-svn: 339400
* [clang-tidy] fix PR36489 - respect deduced pointer types from auto as wellJonas Toth2018-07-231-2/+6
| | | | | | | | | | | | | | | | | | | | Summary: The cppcoreguidelines-pro-bounds-pointer-arithmetic warns on all occassion where pointer arithmetic is used, but does not check values where the pointer types is deduced via `auto`. This patch adjusts this behaviour and solved PR36489. I accidentally commited a wrong patch, this Differential is meant to have a correct revision description and code attached to it. Because the patch was accepted by aaron.ballman already, i will just commit it. See https://reviews.llvm.org/D48717 for the old differntial (contains wrong code from the mixup) Subscribers: nemanjai, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D49682 llvm-svn: 337716
* [clang-tidy] new cppcoreguidelines-narrowing-conversions check.Clement Courbet2018-05-234-0/+111
| | | | | | | | | | | | | | | | | | | Summary: Checks for narrowing conversions, e.g. int i = 0; i += 0.1; This has what some might consider false positives for: i += ceil(d); Reviewers: alexfh, hokein Subscribers: srhines, nemanjai, mgorny, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38455 llvm-svn: 333066
* [tidy] Move private ast matchers into anonymous namespaces to avoid ODR ↵Benjamin Kramer2018-02-182-0/+4
| | | | | | | | conflicts. No functionality change intended. llvm-svn: 325467
* Removed Unicode BOM.Alexander Kornienko2018-01-251-1/+1
| | | | llvm-svn: 323431
* [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-init if ↵Malcolm Parsons2018-01-231-2/+3
| | | | | | | | | | | | | | | | | | using C++2a Summary: C++2a allows bitfields to have default member initializers. Add support for this to clang-tidy's cppcoreguidelines-pro-type-member-init check. Reviewers: aaron.ballman, alexfh Reviewed By: aaron.ballman Subscribers: klimek, nemanjai, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D42426 llvm-svn: 323227
* [clang-tidy] implement check for gotoJonas Toth2018-01-174-0/+95
| | | | | | | | | | | | | | | | | | | | The usage of `goto` is discourage in C++ since forever. This check implements a warning for every `goto`. Even though there are (rare) valid use cases for `goto`, better high level constructs should be used. `goto` is used sometimes in C programs to free resources at the end of functions in the case of errors. This pattern is better implemented with RAII in C++. Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: lebedev.ri, jbcoe, Eugene.Zelenko, klimek, nemanjai, mgorny, xazax.hun, kbarton, cfe-commits Differential Revision: https://reviews.llvm.org/D41815 llvm-svn: 322626
* [clang-tidy] introduce legacy resource functions to ↵Jonas Toth2017-10-182-4/+91
| | | | | | | | | | | | | | | | | | | | | | | | | 'cppcoreguidelines-owning-memory' Summary: This patch introduces support for legacy C-style resource functions that must obey the 'owner<>' semantics. - added legacy creators like malloc,fopen,... - added legacy consumers like free,fclose,... This helps codes that mostly benefit from owner: Legacy, C-Style code that isn't feasable to port directly to RAII but needs a step in between to identify actual resource management and just using the resources. Reviewers: aaron.ballman, alexfh, hokein Reviewed By: aaron.ballman Subscribers: nemanjai, JDevlieghere, xazax.hun, kbarton Differential Revision: https://reviews.llvm.org/D38396 llvm-svn: 316092
* [clang-tidy] Emit note for variable declaration that are later deletedJonas Toth2017-10-041-4/+14
| | | | | | | | | | This patch introduces a note for variable declaration that are later deleted. Adds FIXME notes for possible automatic type-rewriting positions as well. Reviewed by aaron.ballman Differential: https://reviews.llvm.org/D38411 llvm-svn: 314913
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-124-0/+364
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This check implements the typebased semantic of `gsl::owner`. Meaning, that - only `gsl::owner` is allowed to get `delete`d - `new` expression must be assigned to `gsl::owner` - function calls that expect `gsl::owner` as argument, must get either an owner or a newly created and recognized resource (in the moment only `new`ed memory) - assignment to `gsl::owner` must be either a resource or another owner - functions returning an `gsl::owner` are considered as factories, and their result must be assigned to an `gsl::owner` - classes that have an `gsl::owner`-member must declare a non-default destructor There are some problems that occur when typededuction is in place. For example `auto Var = function_that_returns_owner();` the type of `Var` will not be an `gsl::owner`. This case is catched, and explicitly noted. But cases like fully templated functions ``` template <typename T> void f(T t) { delete t; } // ... f(gsl::owner<int*>(new int(42))); ``` Will created false positive (the deletion is problematic), since the type deduction removes the wrapping `typeAlias`. Codereview in D36354 llvm-svn: 313067
* [clang-tidy] Revert Implement type-based check for gsl::ownerJonas Toth2017-09-124-363/+0
| | | | | | This should unbreak the buildbot for visual studio 2015 for now. llvm-svn: 313059
* [clang-tidy] Implement type-based check for `gsl::owner`Jonas Toth2017-09-124-0/+363
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This check implements the typebased semantic of `gsl::owner`. Meaning, that - only `gsl::owner` is allowed to get `delete`d - `new` expression must be assigned to `gsl::owner` - function calls that expect `gsl::owner` as argument, must get either an owner or a newly created and recognized resource (in the moment only `new`ed memory) - assignment to `gsl::owner` must be either a resource or another owner - functions returning an `gsl::owner` are considered as factories, and their result must be assigned to an `gsl::owner` - classes that have an `gsl::owner`-member must declare a non-default destructor There are some problems that occur when typededuction is in place. For example `auto Var = function_that_returns_owner();` the type of `Var` will not be an `gsl::owner`. This case is catched, and explicitly noted. But cases like fully templated functions ``` template <typename T> void f(T t) { delete t; } // ... f(gsl::owner<int*>(new int(42))); ``` Will created false positive (the deletion is problematic), since the type deduction removes the wrapping `typeAlias`. Please give your comments :) llvm-svn: 313043
* [cppcoreguidelines] Don't rely on SmallPtrSet iteration order.Benjamin Kramer2017-08-301-15/+14
| | | | | | | The fixit emission breaks if the iteration order changes and also missed to emit fixits for some edge cases. llvm-svn: 312166
* [clang-tidy] test commit for granted accessJonas Toth2017-08-301-1/+1
| | | | llvm-svn: 312102
* [clang-tidy] Unify the way IncludeStyle and HeaderFileExtesions options are usedAlexander Kornienko2017-07-201-1/+1
| | | | llvm-svn: 308605
* [clang-tidy] Resolve cppcoreguidelines-pro-type-member-init false positiveJonas Devlieghere2017-07-031-0/+3
| | | | | | | | | | | | | | | | Summary: https://bugs.llvm.org/show_bug.cgi?id=33557 Reviewers: Eugene.Zelenko, alexfh, aaron.ballman, hokein Reviewed By: aaron.ballman, hokein Subscribers: cfe-commits, nemanjai, xazax.hun, kbarton Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D34932 llvm-svn: 307040
* Spelling mistakes in comments. NFCI.Simon Pilgrim2017-03-301-3/+3
| | | | | | Based on corrections mentioned in patch for clang for PR27635 llvm-svn: 299074
* Reverting r298421 due to using a header that's unavailable to all systems ↵Aaron Ballman2017-03-221-23/+4
| | | | | | and some other post-commit review feedback. llvm-svn: 298470
* Apply clang-tidy's performance-unnecessary-value-param to clang-tidy.Benjamin Kramer2017-03-211-1/+1
| | | | | | No functionality change intended. llvm-svn: 298442
* Don't make unqualified calls to functions that could well be found viaChandler Carruth2017-03-211-2/+2
| | | | | | | | | | | | | | | ADL as reasonable extension points. All of this would be cleaner if this code followed the more usual LLVM convention of not having deeply nested namespaces inside of .cpp files and instead having a `using namespace ...;` at the top. Then the static function would be in the global namespace and easily referred to as `::join`. Instead we have to write a fairly contrived qualified name. I figure the authors can clean this up with a less ambiguous name, using the newly provided LLVM `join` function, or any other solution, but this at least fixes the build. llvm-svn: 298434
* Prevent cppcoreguidelines-pro-bounds-array-to-pointer-decay from diagnosing ↵Aaron Ballman2017-03-211-4/+23
| | | | | | | | array to pointer decay stemming from system macros. Patch by Breno Rodrigues Guimaraes. llvm-svn: 298421
* Add the 'AllowSoleDefaultDtor' and 'AllowMissingMoveFunctions' options to ↵Aaron Ballman2017-03-132-31/+92
| | | | | | | | the cppcoreguidelines-special-member-functions check. Patch by Florian Gross. llvm-svn: 297671
* [clang-tidy] Function names configurable for cppcoreguidelines-nomalloc - ↵Alexander Kornienko2017-03-022-9/+47
| | | | | | | | | | | | | | | | | | | | | | | | checker Summary: Hello everybody, this is an incremental patch for the NoMalloc-Checker I wrote. It allows to configure the memory-management functions, that are checked, This might be helpful for a code base with custom functions in use, or non-standard functionality, like posix_memalign. Reviewers: aaron.ballman, hokein, alexfh Reviewed By: aaron.ballman, alexfh Subscribers: sbenza, nemanjai, JDevlieghere Tags: #clang-tools-extra Patch by Jonas Toth! Differential Revision: https://reviews.llvm.org/D28239 llvm-svn: 296734
* [clang-tidy] getPreviousNonCommentToken -> getPreviousTokenAlexander Kornienko2017-02-061-2/+2
| | | | llvm-svn: 294192
* [clang-tidy] cppcoreguidelines-slicing: display discarded state size in bytesClement Courbet2016-12-221-2/+3
| | | | | | https://reviews.llvm.org/D27212 llvm-svn: 290340
* modernize-use-auto NFC fixesPiotr Padlewski2016-12-142-4/+3
| | | | llvm-svn: 289656
* [Clang-tidy] check for malloc, realloc and free callsAlexander Kornienko2016-12-134-0/+109
| | | | | | | | | | | | | | | | | | | | | | | Summary: This checker flags the use of C-style memory management functionality and notes about modern alternatives. In an earlier revision it tried to autofix some kind of patterns, but that was a bad idea. Since memory management can be so widespread in a program, manual updating is most likely necessary. Maybe for special cases, there could be later additions to this basic checker. This is the first checker I wrote and I never did something with clang (only compiling programs). So whenever I missed conventions or did plain retarded stuff, feel free to point it out! I am willing to fix them and write a better checker. I hope the patch does work, I never did this either. On a testapply in my repository it did, but I am pretty unconfident in my patching skills :) Reviewers: aaron.ballman, hokein, alexfh, malcolm.parsons Subscribers: cfe-commits, JDevlieghere, nemanjai, Eugene.Zelenko, Prazek, mgorny, modocache Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26167 Patch by Jonas Toth! llvm-svn: 289546
* [clang-tools-extra] Format sources with clang-format. NFC.Mandeep Singh Grang2016-11-0810-28/+29
| | | | | | | | | | | | | | | | Summary: Ran clang-format on all .c/.cpp/.h files in clang-tools-extra. Excluded the test, unittests, clang-reorder-fields, include-fixer, modularize and pptrace directories. Reviewers: klimek, alexfh Subscribers: nemanjai Tags: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D26329 llvm-svn: 286221
* [clang-tidy] Handle bitfields in cppcoreguidelines-pro-type-member-initMalcolm Parsons2016-11-011-2/+4
| | | | | | | | | | | | | | Summary: Unnamed bitfields cannot be initialized. Bitfields cannot be in-class initialized. Reviewers: alexfh, hokein, aaron.ballman Subscribers: Prazek, nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D26119 llvm-svn: 285752
* [clang-tidy] Don't use a SmallSetVector of an enum.Justin Lebar2016-10-212-5/+10
| | | | | | | | | | | | | | | Summary: This doesn't work after converting SmallSetVector to use DenseSet. Instead we can just use a SmallVector. Reviewers: timshen Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D25647 llvm-svn: 284873
* [clang-tidy] Fix an assertion failure in cppcoreguidelines-pro-type-member-init.Haojian Wu2016-10-201-0/+5
| | | | | | | | | | | | | | | Summary: The matcher for matching "class with default constructor" still match some classes without default constructor, which trigger an assert at Line 307. This patch makes the matcher more strict. Reviewers: aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D25747 llvm-svn: 284727
* [clang-tidy] Ignore empty members and bases in ↵Malcolm Parsons2016-10-111-1/+24
| | | | | | | | | | | | | | cppcoreguidelines-pro-type-member-init Summary: Empty/incomplete variables/members/bases don't need to be initialized Reviewers: mgehre, aaron.ballman, alexfh Subscribers: nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D25238 llvm-svn: 283886
* Fix some false-positives with cppcoreguidelines-pro-type-member-init. Handle ↵Aaron Ballman2016-10-042-35/+62
| | | | | | | | | | classes with default constructors that are defaulted or are not present in the AST. Classes with virtual methods or virtual bases are not trivially default constructible, so their members and bases need to be initialized. Patch by Malcolm Parsons. llvm-svn: 283224
* [clang-tidy] Cleaning up language options.Gabor Horvath2016-09-241-3/+2
| | | | | | Differential Revision: https://reviews.llvm.org/D24881 llvm-svn: 282319
* [clang-tidy] Fix segfault in cppcore-guidelines-special-member-functions checkJonathan Coe2016-08-022-21/+18
| | | | | | | | | | | | | | | | | | | | Summary: Use a set rather than a vector of defined special member functions so that multiple declarations of the same function are only counted once. Move some private static member functions into the cpp file. Run clang-format on header. Reviewers: ericLemanissier, Prazek, aaron.ballman Subscribers: Prazek, cfe-commits, nemanjai Projects: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D23008 llvm-svn: 277523
* [clang-tidy] remove trailing whitespaces and retabKirill Bobyrev2016-08-016-9/+9
| | | | llvm-svn: 277340
* [clang-tidy] add check cppcoreguidelines-special-member-functionsJonathan Coe2016-07-304-0/+238
| | | | | | | | | | | | | | | | | | | Summary: Check for classes that violate the rule of five and zero as specified in CppCoreGuidelines: "If a class defines or deletes a default operation then it should define or delete them all." https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-default-operation-define-or-delete-them-all. Reviewers: alexfh, sbenza, aaron.ballman Subscribers: Prazek, Eugene.Zelenko, cfe-commits, ericLemanissier, nemanjai Projects: #clang-tools-extra Differential Revision: https://reviews.llvm.org/D22513 llvm-svn: 277262
* Revert "Revert "[clang-tidy] new cppcoreguidelines-slicing""Clement Courbet2016-07-224-0/+184
| | | | | | Second try for r276408 llvm-svn: 276415
* Revert "[clang-tidy] new cppcoreguidelines-slicing"Clement Courbet2016-07-224-184/+0
| | | | | | Tests fail on clang-x64-ninja-win7 due to too narrow expectation. llvm-svn: 276413
* [clang-tidy] new cppcoreguidelines-slicingClement Courbet2016-07-224-0/+184
| | | | | | | | | | | | Flags slicing of member variables or vtable. See: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es63-dont-slice https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c145-access-polymorphic-objects-through-pointers-and-references Differential revision: http://reviews.llvm.org/D21974 llvm-svn: 276408
* cppcoreguidelines-pro-bounds-constant-array-index: ignore implicit constructorMatthias Gehre2016-07-191-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Summary: The code struct A { int x[3]; }; gets an compiler-generated copy constructor that uses ArraySubscriptExpr (see below). Previously, the check would generate a warning on that copy constructor. This commit disables the warning on implicitly generated code. AST: |-CXXConstructorDecl 0x337b3c8 <col:8> col:8 implicit used constexpr A 'void (const struct A &) noexcept' inline | |-ParmVarDecl 0x337b510 <col:8> col:8 used 'const struct A &' | |-CXXCtorInitializer Field 0x3379238 'x' 'int [3]' | | `-ImplicitCastExpr 0x337e158 <col:8> 'int' <LValueToRValue> | | `-ArraySubscriptExpr 0x337e130 <col:8> 'const int' lvalue | | |-ImplicitCastExpr 0x337e118 <col:8> 'const int *' <ArrayToPointerDecay> | | | `-MemberExpr 0x337dfc8 <col:8> 'int const[3]' lvalue .x 0x3379238 | | | `-DeclRefExpr 0x337dfa0 <col:8> 'const struct A' lvalue ParmVar 0x337b510 '' 'const struct A &' | | `-ImplicitCastExpr 0x337e098 <col:8> 'unsigned long' <LValueToRValue> | | `-DeclRefExpr 0x337e070 <col:8> 'unsigned long' lvalue Var 0x337e010 '__i0' 'unsigned long' Reviewers: alexfh, aaron.ballman Subscribers: aemerson, nemanjai, cfe-commits Differential Revision: https://reviews.llvm.org/D22381 llvm-svn: 275993
* cppcoreguidelines-pro-bounds-constant-array-index: crash for value dependent ↵Matthias Gehre2016-07-141-0/+4
| | | | | | | | | | | | | | | | | | | | | | index in c++03 mode Summary: When the expression is value dependent, isIntegerConstantExpr() crashes in C++03 mode with ../tools/clang/lib/AST/ExprConstant.cpp:9330: (anonymous namespace)::ICEDiag CheckICE(const clang::Expr *, const clang::ASTContext &): Assertion `!E->isValueDependent() && "Should not see value dependent exprs!"' failed. In C++11 mode, that assert does not trigger. This commit works around this in the check. We don't check value-dependent indices and instead check their specialization. Reviewers: alexfh, aaron.ballman Subscribers: nemanjai, cfe-commits Differential Revision: http://reviews.llvm.org/D22190 llvm-svn: 275461
* Fixed cppcoreguidelines-pro-type-member-init when checking records with ↵Haojian Wu2016-05-101-32/+30
| | | | | | | | | | | | | | | | | | indirect fields Summary: Fixed a crash in cppcoreguidelines-pro-type-member-init when checking record types with indirect fields pre-C++11. Fixed handling of indirect fields so they are properly checked and suggested fixes are proposed. Patch by Michael Miller! Reviewers: aaron.ballman, alexfh, hokein Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19993 llvm-svn: 269024
* [clang-tidy] New: checker misc-unconventional-assign-operator replacing ↵Gabor Horvath2016-05-041-2/+2
| | | | | | | | | | | | | | misc-assign-operator-signature Summary: Finds return statements in assign operator bodies where the return value is different from '*this'. Only assignment operators with correct return value Class& are checked. Reviewers: aaron.ballman, alexfh, sbenza Subscribers: o.gyorgy, baloghadamsoftware, LegalizeAdulthood, aaron.ballman, Eugene.Zelenko, xazax.hun, cfe-commits Differential Revision: http://reviews.llvm.org/D18265 llvm-svn: 268492
* Fix a crash in cppcoreguidelines-pro-type-member-init when checking a class ↵Haojian Wu2016-05-031-2/+2
| | | | | | | | | | | | | | | | that initializes itself as a base Summary: Fix a crash when a record type initializes itself in its own base class initializer list. Patch by Michael Miller! Reviewers: alexfh, aaron.ballman, hokein Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19802 llvm-svn: 268369
* [clang-tidy] Cleanup namespace in utils folder.Etienne Bergeron2016-05-033-9/+10
| | | | | | | | | | | | | | Summary: This is a step forward cleaning up the namespaces in clang-tidy/utils. There is no behavior change. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19819 llvm-svn: 268356
* [clang-tidy] ProTypeMemberInitCheck - check that field decls do not have ↵Felix Berger2016-05-031-0/+2
| | | | | | | | | | | | in-class initializer. Reviewers: alexfh, JVApen, aaron.ballman Subscribers: flx, aaron.ballman, cfe-commits Differential Revision: http://reviews.llvm.org/D18300 llvm-svn: 268352
OpenPOWER on IntegriCloud